Annotation of cvsweb/cvsweb.cgi, Revision 3.163
3.55 knu 1: #!/usr/bin/perl -wT
1.1 jfieber 2: #
3.1 knu 3: # cvsweb - a CGI interface to CVS trees.
1.1 jfieber 4: #
3.12 knu 5: # Written in their spare time by
3.113 scop 6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
8: # Henrik Nordstrom <hno@hem.passagen.se>
9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
12: # Jens-Uwe Mager <jum@helios.de>
13: # Ville Skyttä <scop@FreeBSD.org>
14: # Vassilii Khachaturov <vassilii@tarunz.org>
3.1 knu 15: #
16: # Based on:
17: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
3.5 knu 18: # http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1 jfieber 19: #
1.21 wosch 20: # Copyright (c) 1996-1998 Bill Fenner
3.1 knu 21: # (c) 1998-1999 Henner Zeller
3.109 scop 22: # (c) 1999 Henrik Nordstrom
23: # (c) 2000-2002 Akinori MUSHA
3.148 scop 24: # (c) 2002-2003 Ville Skyttä
1.21 wosch 25: # All rights reserved.
26: #
27: # Redistribution and use in source and binary forms, with or without
28: # modification, are permitted provided that the following conditions
29: # are met:
30: # 1. Redistributions of source code must retain the above copyright
31: # notice, this list of conditions and the following disclaimer.
32: # 2. Redistributions in binary form must reproduce the above copyright
33: # notice, this list of conditions and the following disclaimer in the
34: # documentation and/or other materials provided with the distribution.
35: #
36: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46: # SUCH DAMAGE.
47: #
3.87 knu 48: # $FreeBSD$
3.82 knu 49: # $Id: cvsweb.cgi,v 1.112 2001/07/24 13:03:16 hzeller Exp $
3.85 knu 50: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.84 2001/10/07 20:50:10 knu Exp $
1.21 wosch 51: #
3.1 knu 52: ###
53:
3.138 scop 54: require 5.005_03;
3.55 knu 55:
3.1 knu 56: use strict;
1.21 wosch 57:
3.1 knu 58: use vars qw (
3.121 scop 59: $VERSION
3.144 scop 60: $config $allow_version_select
3.120 scop 61: @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr
62: %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
63: @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
3.129 scop 64: %alltags %fileinfo %tags @branchnames %nameprinted
3.120 scop 65: %symrev %revsym @allrevisions %date %author @revdisplayorder
3.152 scop 66: @revisions %state %difflines %log %branchpoint @revorder $keywordsubstitution
3.120 scop 67: $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi
68: $checkoutMagic $doCheckout $scriptname $scriptwhere
69: $where $pathinfo $Browser $nofilelinks $maycompress
3.129 scop 70: @stickyvars @unsafevars %funcline_regexp $is_mod_perl
3.120 scop 71: $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
72: %input $query $barequery $sortby $bydate $byrev $byauthor
73: $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
3.156 scop 74: $charset $output_filter
3.132 scop 75: $command_path %CMD $allow_compress $backicon $diricon $fileicon $graphicon
3.152 scop 76: $fullname $newname $cvstreedefault $logo $defaulttitle $address $binfileicon
3.131 scop 77: $long_intro $short_instruction $shortLogLen $show_author
3.129 scop 78: $tablepadding $hr_breakable $showfunc $hr_ignwhite $hr_ignkeysubst
79: $inputTextSize $mime_types $allow_annotate $allow_markup
3.120 scop 80: $allow_log_extra $allow_dir_extra $allow_source_extra
3.132 scop 81: $allow_cvsgraph $cvsgraph_config $use_java_script $open_extern_window
3.120 scop 82: $extern_window_width $extern_window_height $edit_option_form
3.144 scop 83: $show_subdir_lastmod $show_log_in_markup $preformat_in_markup
3.120 scop 84: $tabstop $state $annTable $sel $curbranch @HideModules @ForbiddenFiles
3.163 ! scop 85: $module $use_descriptions %descriptions @mytz $dwhere
3.139 scop 86: $use_moddate $has_zlib $gzip_open $file_list_len
3.120 scop 87: $allow_tar @tar_options @gzip_options @zip_options @cvs_options
3.128 scop 88: @annotate_options $LOG_FILESEPARATOR $LOG_REVSEPARATOR
3.144 scop 89: $tmpdir $HTML_DOCTYPE $HTML_META $cssurl $TempTemplate $CSS
3.148 scop 90: $CvsWebMarkupRE $allow_enscript @enscript_options %enscript_types
3.156 scop 91: $MimeTypes
3.1 knu 92: );
93:
3.125 scop 94: # TODO:
95: # Maybe "use filetest 'access'" on perl >= 5.6 for better -X checks.
96: #($] >= 5.006) and eval "use filetest 'access'";
97:
3.138 scop 98: use Cwd qw(abs_path);
99: use File::Basename qw();
100: use File::Temp qw(tempdir);
101: use IO::Pipe qw();
102: use IPC::Open2 qw(open2);
103: use Time::Local qw();
3.122 scop 104:
105: # -----------------------------------------------------------------------------
106:
107: # All global initialization that can be done in compile time should go to
108: # the BEGIN block. Persistent environments, such as mod_perl, will benefit
109: # from this.
110:
111: BEGIN
112: {
113: $VERSION = '3.0-dev';
114:
115: $HTML_DOCTYPE =
116: '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
117:
118: $HTML_META = <<EOM;
119: <meta name="robots" content="nofollow">
120: <meta name="generator" content="FreeBSD-CVSweb $VERSION">
121: <meta http-equiv="Content-Script-Type" content="text/javascript">
122: <meta http-equiv="Content-Style-Type" content="text/css">
123: EOM
124:
125: # Check if the zlib C library interface is installed, and if yes,
126: # we can avoid using the extra gzip process.
127: eval { require Compress::Zlib; };
128: $has_zlib = !$@;
129:
3.156 scop 130: # Use MIME::Types for MIME type lookups if it's available.
131: eval {
132: require MIME::Types;
133: $MimeTypes = MIME::Types->new();
134: };
135: $MimeTypes = undef if $@;
136:
3.122 scop 137: $is_mod_perl = defined($ENV{MOD_PERL});
138:
139: $tmpdir = $ENV{TMPDIR} || '/var/tmp';
140:
3.138 scop 141: $TempTemplate = '.cvsweb.XXXXXXXX';
142:
3.122 scop 143: $LOG_FILESEPARATOR = qr/^={77}$/o;
144: $LOG_REVSEPARATOR = qr/^-{28}$/o;
3.146 scop 145:
146: $CvsWebMarkupRE = qr/^text\/(x-cvsweb|vnd\.viewcvs)-markup$/io;
3.122 scop 147: }
148:
149: # -----------------------------------------------------------------------------
150:
3.12 knu 151: sub printDiffSelect($);
3.37 knu 152: sub printDiffLinks($$);
153: sub printLogSortSelect($);
3.12 knu 154: sub findLastModifiedSubdirs(@);
3.36 knu 155: sub htmlify_sub(&$);
3.12 knu 156: sub htmlify($;$);
3.20 knu 157: sub spacedHtmlText($;$);
3.12 knu 158: sub link($$);
159: sub revcmp($$);
3.103 knu 160: sub fatal($$@);
3.12 knu 161: sub redirect($);
162: sub safeglob($);
3.58 knu 163: sub search_path($);
3.156 scop 164: sub getMimeType($;$);
3.24 knu 165: sub head($;$);
166: sub scan_directives(@);
3.86 knu 167: sub openOutputFilter();
3.133 scop 168: sub doAnnotate($);
3.12 knu 169: sub doCheckout($$);
3.132 scop 170: sub doGraph($);
171: sub doGraphView($);
3.163 ! scop 172: sub cvswebMarkup($$$;$);
3.12 knu 173: sub viewable($);
174: sub doDiff($$$$$$);
175: sub getDirLogs($$@);
176: sub readLog($;$);
177: sub printLog($;$);
178: sub doLog($);
179: sub flush_diff_rows($$$$);
3.144 scop 180: sub human_readable_diff($$);
3.163 ! scop 181: sub navigateHeader($$$$$;$);
3.12 knu 182: sub plural_write($$);
183: sub readableTime($$);
184: sub clickablePath($$);
185: sub chooseCVSRoot();
186: sub chooseMirror();
187: sub fileSortCmp();
188: sub download_url($$;$);
189: sub download_link($$$;$);
3.132 scop 190: sub graph_link($$;$);
3.140 scop 191: sub toggleQuery($;$);
3.12 knu 192: sub urlencode($);
3.35 knu 193: sub htmlquote($);
3.36 knu 194: sub htmlunquote($);
3.48 knu 195: sub hrefquote($);
3.163 ! scop 196: sub http_header(;$$);
! 197: sub html_header($;$);
3.12 knu 198: sub html_footer();
199: sub link_tags($);
3.81 knu 200: sub forbidden_file($);
3.12 knu 201: sub forbidden_module($);
202:
3.1 knu 203: ##### Start of Configuration Area ########
3.122 scop 204:
3.142 scop 205: # Get rid of unsafe environment vars. Don't do this in BEGIN...
206: delete(@ENV{qw(PATH IFS CDPATH ENV BASH_ENV)});
3.59 knu 207:
3.122 scop 208: my ($mydir) = (File::Basename::dirname($0) =~ /(.*)/); # untaint
3.58 knu 209:
3.12 knu 210: # == EDIT this ==
3.28 knu 211: # Locations to search for user configuration, in order:
3.80 knu 212: for ("$mydir/cvsweb.conf", '/usr/local/etc/cvsweb/cvsweb.conf') {
3.120 scop 213: if (defined($_) && -r $_) {
214: $config = $_;
215: last;
216: }
3.11 knu 217: }
3.122 scop 218: undef $mydir;
3.1 knu 219:
220: # == Configuration defaults ==
221: # Defaults for configuration variables that shouldn't need
222: # to be configured..
223: $allow_version_select = 1;
3.120 scop 224: $allow_log_extra = 1;
3.1 knu 225:
226: ##### End of Configuration Area ########
227:
228: ######## Configuration variables #########
229: # These are defined to allow checking with perl -cw
3.120 scop 230:
3.80 knu 231: @CVSrepositories = @CVSROOT = %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS =
3.129 scop 232: %MTYPES = %tags = %alltags = %fileinfo = ();
3.120 scop 233:
3.129 scop 234: $cvstreedefault = $logo = $defaulttitle =
3.120 scop 235: $address = $long_intro = $short_instruction = $shortLogLen = $show_author =
3.131 scop 236: $tablepadding = $hr_breakable = $showfunc = $hr_ignwhite =
3.129 scop 237: $hr_ignkeysubst = $inputTextSize = $mime_types = $allow_annotate =
3.120 scop 238: $allow_markup = $use_java_script = $open_extern_window =
239: $extern_window_width = $extern_window_height = $edit_option_form =
3.144 scop 240: $show_subdir_lastmod = $show_log_in_markup =
3.163 ! scop 241: $tabstop = $use_moddate = $gzip_open = undef;
3.32 knu 242:
3.37 knu 243: @DIFFTYPES = qw(h H u c s);
244: @DIFFTYPES{@DIFFTYPES} = (
3.120 scop 245: {
246: 'descr' => 'colored',
247: 'opts' => ['-u'],
248: 'colored' => 1,
249: },
250: {
251: 'descr' => 'long colored',
252: 'opts' => ['--unified=15'],
253: 'colored' => 1,
254: },
255: {
256: 'descr' => 'unified',
257: 'opts' => ['-u'],
258: 'colored' => 0,
259: },
260: {
261: 'descr' => 'context',
262: 'opts' => ['-c'],
263: 'colored' => 0,
264: },
265: {
266: 'descr' => 'side by side',
267: 'opts' => ['--side-by-side', '--width=164'],
268: 'colored' => 0,
269: },
3.80 knu 270: );
3.37 knu 271:
272: @LOGSORTKEYS = qw(cvs date rev);
273: @LOGSORTKEYS{@LOGSORTKEYS} = (
3.120 scop 274: {'descr' => 'Not sorted',},
275: {'descr' => 'Commit date',},
276: {'descr' => 'Revision',},
3.80 knu 277: );
3.37 knu 278:
3.1 knu 279: ##### End of configuration variables #####
280:
3.120 scop 281: $checkoutMagic = "~checkout~";
282: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
283: $where = $pathinfo;
284: $doCheckout = ($where =~ m|^/$checkoutMagic/|);
285: $where =~ s|^/$checkoutMagic/|/|;
286: $where =~ s|^/||;
287: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
288: $scriptname =~ s|^/*|/|;
3.63 knu 289:
3.64 knu 290: # Let's workaround thttpd's stupidity..
3.63 knu 291: if ($scriptname =~ m|/$|) {
3.120 scop 292: $pathinfo .= '/';
293: my $re = quotemeta $pathinfo;
294: $scriptname =~ s/$re$//;
3.63 knu 295: }
296:
3.120 scop 297: $scriptwhere = $scriptname;
3.63 knu 298: $scriptwhere .= '/' . urlencode($where);
299: $where = '/' if ($where eq '');
3.3 knu 300:
3.1 knu 301: # in lynx, it it very annoying to have two links
302: # per file, so disable the link at the icon
303: # in this case:
3.120 scop 304: $Browser = $ENV{HTTP_USER_AGENT} || '';
3.80 knu 305: $is_links = ($Browser =~ m`^Links `);
306: $is_lynx = ($Browser =~ m`^Lynx/`i);
307: $is_w3m = ($Browser =~ m`^w3m/`i);
308: $is_msie = ($Browser =~ m`MSIE`);
3.5 knu 309: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
3.3 knu 310:
3.34 knu 311: $is_textbased = ($is_links || $is_lynx || $is_w3m);
3.5 knu 312:
313: $nofilelinks = $is_textbased;
3.1 knu 314:
315: # newer browsers accept gzip content encoding
316: # and state this in a header
317: # (netscape did always but didn't state it)
318: # It has been reported that these
319: # braindamaged MS-Internet Exploders claim that they
320: # accept gzip .. but don't in fact and
321: # display garbage then :-/
3.23 knu 322: # Turn off gzip if running under mod_perl and no zlib is available,
323: # piping does not work as expected inside the server.
3.120 scop 324: $maycompress = (
325: ((defined($ENV{HTTP_ACCEPT_ENCODING})
326: && $ENV{HTTP_ACCEPT_ENCODING} =~ /gzip/)
327: || $is_mozilla3)
328: && !$is_msie
329: && !($is_mod_perl && !$has_zlib)
330: );
3.1 knu 331:
332: # put here the variables we need in order
333: # to hold our state - they will be added (with
3.12 knu 334: # their current value) to any link/query string
3.1 knu 335: # you construct
3.149 scop 336: @stickyvars = qw(cvsroot hideattic ignorecase sortby logsort f only_with_tag
337: ln);
3.97 knu 338: @unsafevars = qw(logsort only_with_tag r1 r2 rev sortby tr1 tr2);
1.1 jfieber 339:
3.1 knu 340: if (-f $config) {
3.120 scop 341: do "$config"
342: or fatal("500 Internal Error",
343: 'Error in loading configuration file: %s<br><br>%s<br>',
344: $config, $@);
3.27 knu 345: } else {
3.120 scop 346: fatal("500 Internal Error",
347: 'Configuration not found. Set the variable <code>$config</code> in cvsweb.cgi to your <b>cvsweb.conf</b> configuration file first.');
3.1 knu 348: }
349:
3.144 scop 350: $CSS = $cssurl ?
351: sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">\n",
352: htmlquote($cssurl)) : '';
353:
3.1 knu 354: undef %input;
3.3 knu 355: $query = $ENV{QUERY_STRING};
356:
3.12 knu 357: if (defined($query) && $query ne '') {
3.120 scop 358: foreach (split (/&/, $query)) {
359: y/+/ /;
360: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
361: if (/(\S+)=(.*)/) {
362: $input{$1} = $2 if ($2 ne "");
363: } else {
364: $input{$_}++;
365: }
366: }
1.7 fenner 367: }
1.10 wosch 368:
3.12 knu 369: # For backwards compability, set only_with_tag to only_on_branch if set.
3.1 knu 370: $input{only_with_tag} = $input{only_on_branch}
3.120 scop 371: if (defined($input{only_on_branch}));
3.97 knu 372:
3.154 scop 373: # Prevent cross-site scripting, untaint.
3.97 knu 374: foreach (@unsafevars) {
3.154 scop 375: if (defined($input{$_})) {
376: # Colons are needed in diffs between tags.
3.155 scop 377: if ($input{$_} =~ /^([\w\-.:]*)$/) {
3.154 scop 378: $input{$_} = $1;
379: } else {
380: fatal("500 Internal Error", 'Malformed query (%s=%s)', $_, $input{$_});
381: }
3.120 scop 382: }
3.97 knu 383: }
384:
385: if (defined($input{"content-type"})) {
3.146 scop 386: fatal('500 Internal Error', 'Unsupported content-type')
387: if ($input{"content-type"} !~ /^[-0-9A-Za-z]+\/[-0-9A-Za-z\.]+$/);
3.97 knu 388: }
1.10 wosch 389:
3.158 scop 390: #
391: # CVS roots
392: #
393: my $rootfound = 0;
394: for (my $i = 0; $i < scalar(@CVSrepositories); $i += 2) {
395: my $key = $CVSrepositories[$i];
396: my ($descr, $cvsroot) = @{$CVSrepositories[$i+1]};
397: unless (-d $cvsroot) {
398: warn("Root '$cvsroot' defined in \@CVSrepositories is not a directory, " .
399: 'entry ignored');
400: next;
401: }
402: $rootfound ||= 1;
403: $cvstreedefault = $key unless defined($cvstreedefault);
404: $CVSROOTdescr{$key} = $descr;
405: $CVSROOT{$key} = $cvsroot;
406: push(@CVSROOT, $key);
407: }
408: unless ($rootfound) {
409: fatal('500 Internal Error',
410: 'No valid CVS roots found! See <code>@CVSrepositories</code> in ' .
411: 'your configuration file (<code>%s</code>).',
412: $config);
413: }
414: undef $rootfound;
415:
416: #
417: # Default CVS root
418: #
419: if (!defined($CVSROOT{$cvstreedefault})) {
420: fatal("500 Internal Error",
421: '<code>$cvstreedefault</code> points to a repository (%s) not ' .
422: 'defined in <code>@CVSrepositories</code> in your configuration ' .
423: 'file (<code>%s</code>).',
424: $cvstreedefault,
425: $config);
426: }
427:
3.1 knu 428: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10 wosch 429:
3.120 scop 430: while (my ($key, $defval) = each %DEFAULTVALUE) {
3.80 knu 431:
3.120 scop 432: # Replace not given parameters with defaults.
433: next unless (defined($defval)
3.121 scop 434: && (!defined($input{$key}) || $input{$key} eq ''));
3.120 scop 435:
436: # Empty checkboxes in forms return nothing, so we define a helper variable
437: # in these forms (copt) which indicates that we just set parameters with a
438: # checkbox.
439: if (defined($input{'copt'})) {
440:
441: # 'copt' is defined -> the result of empty input checkbox
442: # -> set to zero (disable) if default is a boolean (0|1).
443: $input{$key} = 0 if ($defval eq '0' || $defval eq '1');
444:
445: } else {
446:
447: # 'copt' isn't defined --> empty input is not the result
448: # of empty input checkbox --> set default.
449: $input{$key} = $defval;
450: }
1.10 wosch 451: }
3.12 knu 452:
3.1 knu 453: $barequery = "";
3.31 knu 454: my @barequery;
3.1 knu 455: foreach (@stickyvars) {
3.80 knu 456:
3.120 scop 457: # construct a query string with the sticky non default parameters set
458: if (defined($input{$_})
459: && $input{$_} ne ''
460: && !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_}))
461: {
462: push @barequery, join ('=', urlencode($_), urlencode($input{$_}));
463: }
3.1 knu 464: }
3.80 knu 465:
3.1 knu 466: # is there any query ?
3.31 knu 467: if (@barequery) {
3.120 scop 468: $barequery = join ('&', @barequery);
469: $query = "?$barequery";
470: $barequery = "&$barequery";
3.80 knu 471: } else {
3.120 scop 472: $query = "";
3.1 knu 473: }
3.31 knu 474: undef @barequery;
3.1 knu 475:
3.120 scop 476: if (defined($input{'path'})) {
477: redirect("$scriptname/$input{path}$query");
3.57 knu 478: }
479:
3.1 knu 480: # get actual parameters
3.144 scop 481: {
482: my $sortby = $input{sortby} || 'file';
483: $bydate = 0;
484: $byrev = 0;
485: $byauthor = 0;
486: $bylog = 0;
487: $byfile = 0;
488: if ($sortby eq 'date') {
489: $bydate = 1;
490: } elsif ($sortby eq 'rev') {
491: $byrev = 1;
492: } elsif ($sortby eq 'author') {
493: $byauthor = 1;
494: } elsif ($sortby eq 'log') {
495: $bylog = 1;
496: } else {
497: $byfile = 1;
498: }
3.1 knu 499: }
500:
3.37 knu 501: $defaultDiffType = $input{'f'};
3.1 knu 502:
3.3 knu 503: $logsort = $input{'logsort'};
3.1 knu 504:
505: # alternate CVS-Tree, configured in cvsweb.conf
506: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
3.120 scop 507: $cvstree = $input{'cvsroot'};
3.1 knu 508: } else {
3.120 scop 509: $cvstree = $cvstreedefault;
1.10 wosch 510: }
511:
3.1 knu 512: $cvsroot = $CVSROOT{$cvstree};
1.10 wosch 513:
3.1 knu 514: # create icons out of description
3.120 scop 515: foreach my $k (keys %ICONS) {
516: my ($itxt, $ipath, $iwidth, $iheight) = @{$ICONS{$k}};
517: no strict 'refs';
518: if ($ipath) {
519: ${"${k}icon"} =
520: sprintf('<img src="%s" alt="%s" border="0" width="%d" height="%d">',
3.132 scop 521: hrefquote($ipath), htmlquote($itxt), $iwidth, $iheight);
3.120 scop 522: } else {
523: ${"${k}icon"} = $itxt;
524: }
1.24 wosch 525: }
526:
3.27 knu 527: my $config_cvstree = "$config-$cvstree";
528:
3.1 knu 529: # Do some special configuration for cvstrees
3.27 knu 530: if (-f $config_cvstree) {
3.120 scop 531: do "$config_cvstree"
532: or fatal("500 Internal Error",
533: 'Error in loading configuration file: %s<br><br>%s<br>',
534: $config_cvstree, $@);
3.27 knu 535: }
3.31 knu 536: undef $config_cvstree;
3.1 knu 537:
3.120 scop 538: $re_prcategories = '(?:' . join ('|', @prcategories) . ')' if @prcategories;
539: $re_prkeyword = quotemeta($prkeyword) if defined($prkeyword);
540: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.24 wosch 541:
3.80 knu 542: $fullname = "$cvsroot/$where";
3.1 knu 543:
3.63 knu 544: my $rewrite = 0;
545:
546: if ($pathinfo =~ m|//|) {
3.120 scop 547: $pathinfo =~ y|/|/|s;
548: $rewrite = 1;
3.63 knu 549: }
550:
3.120 scop 551: if (-d $fullname) {
552: if ($pathinfo !~ m|/$|) {
553: $pathinfo .= '/';
554: $rewrite = 1;
555: }
556: } else {
557: if ($pathinfo =~ m|/$|) {
558: chop $pathinfo;
559: $rewrite = 1;
560: }
3.63 knu 561: }
562:
563: if ($rewrite) {
3.120 scop 564: redirect($scriptname . urlencode($pathinfo) . $query);
3.1 knu 565: }
566:
3.63 knu 567: undef $rewrite;
568:
3.1 knu 569: if (!-d $cvsroot) {
3.120 scop 570: fatal("500 Internal Error",
571: '$CVSROOT not found!<p>The server on which the CVS tree lives is probably down. Please try again in a few minutes.');
3.1 knu 572: }
573:
574: #
575: # See if the module is in our forbidden list.
576: #
577: $where =~ m:([^/]*):;
578: $module = $1;
579: if ($module && &forbidden_module($module)) {
3.120 scop 580: fatal("403 Forbidden", 'Access to %s forbidden.', $where);
3.1 knu 581: }
3.46 knu 582:
583: #
584: # Handle tarball downloads before any headers are output.
585: #
586: if ($input{tarball}) {
3.120 scop 587: fatal('403 Forbidden', 'Downloading tarballs is prohibited.')
588: unless $allow_tar;
589: my ($module) = ($where =~ m,^/?(.*),); # untaint
590: $module =~ s,/([^/]*)$,,;
591: my ($ext) = ($1 =~ /(\.tar\.gz|\.zip)$/);
592: my ($basedir) = ($module =~ m,([^/]+)$,);
593:
594: if ($basedir eq '' || $module eq '') {
595: fatal('500 Internal Error',
596: 'You cannot download the top level directory.');
597: }
598:
3.138 scop 599: my $tmpexportdir;
600: eval {
601: local $SIG{__DIE__};
602: $tmpexportdir = tempdir($TempTemplate, DIR => $tmpdir, CLEANUP => 1);
603: };
604: if ($@) {
605: fatal('500 Internal Error', 'Unable to make temporary directory: %s', $@);
606: }
3.120 scop 607:
608: my @fatal;
609:
610: my $tag =
611: (exists $input{only_with_tag} && length $input{only_with_tag})
612: ? $input{only_with_tag}
613: : 'HEAD';
614:
615: $tag = 'HEAD' if $tag eq 'MAIN';
616:
617: if (system($CMD{cvs},
618: @cvs_options, '-Qd', $cvsroot, 'export', '-r', $tag, '-d',
619: "$tmpexportdir/$basedir", $module))
620: {
3.141 scop 621: @fatal = ('500 Internal Error', 'cvs export failure: %s: %s', $!, $module);
3.120 scop 622: } else {
623: $| = 1; # Essential to get the buffering right.
624:
625: if ($ext eq '.tar.gz') {
626: print "Content-Type: application/x-gzip\r\n\r\n";
627:
628: system("$CMD{tar} @tar_options -cf - -C $tmpexportdir $basedir | $CMD{gzip} @gzip_options -c")
629: and @fatal =
630: ('500 Internal Error', 'tar zc failure: %s: %s', $!, $basedir);
631: } elsif ($ext eq '.zip' && $CMD{zip}) {
632: print "Content-Type: application/zip\r\n\r\n";
633:
634: system("cd $tmpexportdir && $CMD{zip} @zip_options -r - $basedir")
635: and @fatal =
636: ('500 Internal Error', 'zip failure: %s: %s', $!, $basedir);
637: } else {
638: @fatal = ('500 Internal Error', 'unsupported file type');
639: }
640: }
3.46 knu 641:
3.138 scop 642: # File::Temp's CLEANUP will handle cleanup of the temp dir for us.
3.46 knu 643:
3.120 scop 644: &fatal(@fatal) if @fatal;
3.46 knu 645:
3.120 scop 646: exit;
3.46 knu 647: }
648:
3.1 knu 649: ##############################
650: # View a directory
651: ###############################
3.46 knu 652: if (-d $fullname) {
3.120 scop 653: my $dh = do { local (*DH); };
654: opendir($dh, $fullname) or fatal("404 Not Found", '%s: %s', $where, $!);
655: my @dir = readdir($dh);
656: closedir($dh);
657: my @subLevelFiles = findLastModifiedSubdirs(@dir)
658: if ($show_subdir_lastmod);
3.150 scop 659: my @unreadable = getDirLogs($cvsroot, $where, @subLevelFiles);
3.120 scop 660:
661: if ($where eq '/') {
662: html_header($defaulttitle);
663: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
664: print $long_intro;
665: } else {
666: html_header($where);
667: print $short_instruction;
668: }
669:
670: if ($use_descriptions && open(DESC, "<$cvsroot/CVSROOT/descriptions")) {
671: while (<DESC>) {
672: chomp;
673: my ($dir, $description) = /(\S+)\s+(.*)/;
674: $descriptions{$dir} = $description;
675: }
676: close(DESC);
677: }
678:
679: print "<p><a name=\"dirlist\"></a></p>\n";
680:
681: # give direct access to dirs
682: if ($where eq '/') {
683: chooseMirror();
684: chooseCVSRoot();
685: } else {
686: print "<p>Current directory: <b>", &clickablePath($where, 0), "</b></p>\n";
687:
3.153 scop 688: print "<p>Current tag: <b>", htmlquote($input{only_with_tag}), "</b></p>\n"
3.120 scop 689: if $input{only_with_tag};
690:
691: }
692:
693: print "<hr noshade>\n";
694:
3.131 scop 695: my $infocols = 0;
696:
697: print "<table class=\"dir\" width=\"100%\" cellspacing=\"1\" cellpadding=\"$tablepadding\">\n";
698: $infocols++;
3.132 scop 699: printf "<tr>\n<th class=\"dir-header%s\" colspan=\"2\">",
700: $byfile ? '-sorted' : '';
3.131 scop 701:
702: if ($byfile) {
703: print 'File';
704: } else {
705: print &link('File',
706: sprintf('./%s#dirlist', toggleQuery('sortby', 'file')));
707: }
708: print "</th>\n";
3.120 scop 709:
3.131 scop 710: # Do not display the other column headers if we do not have any files
711: # with revision information.
712: if (scalar(%fileinfo)) {
3.120 scop 713: $infocols++;
3.131 scop 714: printf '<th class="dir-header%s">', $byrev ? '-sorted' : '';
3.120 scop 715:
3.131 scop 716: if ($byrev) {
717: print 'Rev.';
3.120 scop 718: } else {
3.131 scop 719: print &link('Rev.',
720: sprintf('./%s#dirlist', toggleQuery('sortby', 'rev')));
3.120 scop 721: }
722: print "</th>\n";
3.131 scop 723: $infocols++;
724: printf '<th class="dir-header%s">', $bydate ? '-sorted' : '';
3.120 scop 725:
3.131 scop 726: if ($bydate) {
727: print 'Age';
728: } else {
729: print &link('Age',
730: sprintf('./%s#dirlist', toggleQuery('sortby', 'date')));
731: }
732: print "</th>\n";
3.120 scop 733:
3.131 scop 734: if ($show_author) {
3.120 scop 735: $infocols++;
3.131 scop 736: printf '<th class="dir-header%s">', $byauthor ? '-sorted' : '';
3.120 scop 737:
3.131 scop 738: if ($byauthor) {
739: print 'Author';
3.120 scop 740: } else {
3.131 scop 741: print
742: &link('Author',
743: sprintf('./%s#dirlist', toggleQuery('sortby', 'author')));
3.120 scop 744: }
745: print "</th>\n";
3.131 scop 746: }
747: $infocols++;
748: printf '<th class="dir-header%s">', $bylog ? '-sorted' : '';
3.120 scop 749:
3.131 scop 750: if ($bylog) {
751: print 'Last log entry';
752: } else {
753: print &link('Last log entry',
754: sprintf('./%s#dirlist', toggleQuery('sortby', 'log')));
3.120 scop 755: }
3.131 scop 756: print "</th>\n";
757: } elsif ($use_descriptions) {
758: print "<th class=\"dir-header\">Description</th>\n";
759: $infocols++;
3.120 scop 760: }
3.131 scop 761: print "</tr>\n";
762:
3.120 scop 763: my $dirrow = 0;
764:
765: my $i;
766: lookingforattic:
767: for ($i = 0; $i <= $#dir; $i++) {
768: if ($dir[$i] eq "Attic") {
769: last lookingforattic;
770: }
771: }
772:
773: if (!$input{'hideattic'}
774: && ($i <= $#dir)
775: && opendir($dh, $fullname . '/Attic'))
776: {
777: splice(@dir, $i, 1, grep((s|^|Attic/|, !m|/\.|), readdir($dh)));
778: closedir($dh);
779: }
780:
781: my $hideAtticToggleLink =
782: $input{'hideattic'}
783: ? ''
784: : &link('[Hide]', sprintf('./%s#dirlist', &toggleQuery('hideattic')));
785:
786: # Sort without the Attic/ pathname.
787: # place directories first
788:
789: my $attic;
790: my $url;
791: my $fileurl;
792: my $filesexists;
793: my $filesfound;
794:
795: foreach my $file (sort { &fileSortCmp } @dir) {
796:
797: next if ($file eq '.');
798:
799: # ignore CVS lock and stale NFS files
800: next if ($file =~ /^\#cvs\.|^,|^\.nfs/); # \# for XEmacs cperl-mode...
801:
802: # Check whether to show the CVSROOT path
803: next if ($input{'hidecvsroot'} && $file eq 'CVSROOT');
804:
805: # Check whether the module is in the restricted list
806: next if ($file && &forbidden_module($file));
807:
3.150 scop 808: # Is it a directory?
809: my $isdir = -d "$fullname/$file";
810:
811: # Ignore non-readable files and directories?
812: next if ($input{'hidenonreadable'} && (! -r _ || ($isdir && ! -x _)));
3.120 scop 813:
814: if ($file =~ s|^Attic/||) {
3.131 scop 815: $attic = ' (in the Attic) ' . $hideAtticToggleLink;
3.120 scop 816: } else {
817: $attic = '';
818: }
819:
3.150 scop 820: if ($file eq '..' || $isdir) {
3.120 scop 821: next if ($file eq '..' && $where eq '/');
3.152 scop 822: my ($rev, $date, $log, $author, $filename, $keywordsubst) =
823: @{$fileinfo{$file}} if (defined($fileinfo{$file}));
3.132 scop 824: printf "<tr class=\"dir-row-%s\">\n<td colspan=\"2\">",
825: ($dirrow % 2) ? 'even' : 'odd';
3.120 scop 826:
827: if ($file eq '..') {
828: $url = "../$query";
829: if ($nofilelinks) {
830: print $backicon;
831: } else {
832: print &link($backicon, $url);
833: }
834: print ' ', &link("Parent Directory", $url);
835: } else {
836: $url = './' . urlencode($file) . "/$query";
3.136 scop 837: print '<a name="', hrefquote($file), '"></a>';
3.120 scop 838:
839: if ($nofilelinks) {
840: print $diricon;
841: } else {
842: print &link($diricon, $url);
843: }
3.136 scop 844: print ' ', &link(htmlquote("$file/"), $url), $attic;
3.120 scop 845:
846: if ($file eq "Attic") {
847: print " ";
848: print &link('[Don\'t hide]',
849: sprintf('./%s#dirlist', &toggleQuery('hideattic')));
850: }
851: }
852:
853: # Show last change in dir
854: if ($filename) {
3.131 scop 855: print "</td>\n<td> </td>\n<td> ";
856:
3.120 scop 857: if ($date) {
858: print " <i>", readableTime(time() - $date, 0), "</i>";
859: }
860:
861: if ($show_author) {
3.136 scop 862: print "</td>\n<td> ", htmlquote($author);
3.120 scop 863: }
3.131 scop 864: print "</td>\n<td> ";
3.120 scop 865: $filename =~ s%^[^/]+/%%;
3.136 scop 866: print htmlquote($filename), '/', $rev, '<br>';
3.120 scop 867:
868: if ($log) {
869: print ' <span style="font-size: smaller">',
870: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
871: print '...' if (length($log) > 80);
872: print '</span>';
873: }
874: } else {
875: my $dwhere = ($where ne '/' ? $where : '') . $file;
876:
877: if ($use_descriptions && defined $descriptions{$dwhere}) {
3.131 scop 878: print '<td colspan="', ($infocols - 1), '"> ';
3.120 scop 879: print $descriptions{$dwhere};
880:
3.131 scop 881: } elsif ($infocols > 1) {
3.120 scop 882:
883: # close the row with the appropriate number of
884: # columns, so that the vertical seperators are visible
885: my ($cols) = $infocols;
886: while ($cols > 1) {
887: print "</td>\n<td> ";
888: $cols--;
889: }
890: }
891: }
892:
3.131 scop 893: print "</td>\n</tr>\n";
3.120 scop 894: $dirrow++;
3.131 scop 895:
3.120 scop 896: } elsif ($file =~ s/,v$//) {
897:
898: # Skip forbidden files now so we'll give no hint
899: # about their existence. This should probably have
900: # been done earlier, but it's straightforward here.
901: next if forbidden_file("$fullname/$file");
902:
903: $fileurl = ($attic ? 'Attic/' : '') . urlencode($file);
904: $url = './' . $fileurl . $query;
905: $filesexists++;
906: next if (!defined($fileinfo{$file}));
3.152 scop 907: my ($rev, $date, $log, $author, $filename, $keywordsubst) =
908: @{$fileinfo{$file}};
3.156 scop 909: my $isbinary = $keywordsubst eq 'b' ? 1 : 0;
3.120 scop 910: $filesfound++;
3.156 scop 911:
3.132 scop 912: printf "<tr class=\"dir-row-%s\">\n", ($dirrow % 2) ? 'even' : 'odd';
913: printf '<td%s>', $allow_cvsgraph ? '' : ' colspan="2"';
3.120 scop 914:
3.156 scop 915: my $icon = $isbinary ? $binfileicon : $fileicon;
3.120 scop 916: if ($nofilelinks) {
3.152 scop 917: print $icon;
3.120 scop 918: } else {
3.152 scop 919: print &link($icon, $url);
3.120 scop 920: }
921: print ' ', &link(htmlquote($file), $url), $attic;
3.132 scop 922: if ($allow_cvsgraph) {
923: print '</td><td>', &graph_link($fileurl, $rev);
924: }
925: print "</td>\n<td width=\"30\"> ";
3.120 scop 926: download_link($fileurl, $rev, $rev,
3.156 scop 927: viewable(getMimeType($file, $isbinary)) ?
928: 'text/x-cvsweb-markup' : undef);
3.131 scop 929: print "</td>\n<td> ";
3.120 scop 930:
931: if ($date) {
932: print " <i>", readableTime(time() - $date, 0), "</i>";
933: }
934: if ($show_author) {
3.136 scop 935: print "</td>\n<td> ", htmlquote($author);
3.120 scop 936: }
3.131 scop 937: print "</td>\n<td> ";
3.120 scop 938:
939: if ($log) {
940: print ' <span style="font-size: smaller">',
941: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
942: print '...' if (length $log > 80);
943: print '</span>';
944: }
3.131 scop 945: print "</td>\n</tr>";
3.120 scop 946: $dirrow++;
947: }
948: print "\n";
949: }
950:
3.131 scop 951: print "</table>\n";
3.120 scop 952:
3.150 scop 953: if ((my $num = scalar(@unreadable)) && ! $input{hidenonreadable}) {
954: printf(<<EOF, $num, htmlquote(join(', ', @unreadable)));
955: <p>
956: <b>NOTE:</b> The following %d unreadable files were ignored:<br>
957: <em>%s</em>
958: </p>
959: EOF
960: }
961:
3.120 scop 962: if ($filesexists && !$filesfound) {
3.150 scop 963: my $currtag = defined($input{only_with_tag}) ?
964: sprintf(' (%s)', htmlquote($input{only_with_tag})) : '';
965: printf(<<EOF, $filesexists, $currtag);
966: <p>
967: <b>NOTE:</b> There are %d files, but none matches the current tag%s.
968: </p>
969: EOF
3.120 scop 970: }
971:
972: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
973: %tags = %alltags;
974: }
975:
976: if (scalar %tags
977: || $input{only_with_tag}
978: || $edit_option_form
979: || defined($input{"options"}))
980: {
981: print "<hr size=\"1\" noshade>\n";
982: }
983:
984: if (scalar %tags || $input{only_with_tag}) {
985: print "<form method=\"get\" action=\"./\">\n";
986: foreach my $var (@stickyvars) {
3.154 scop 987: printf("<input type=\"hidden\" name=\"$var\" value=\"%s\">\n",
988: htmlquote($input{$var}))
3.120 scop 989: if (defined($input{$var})
990: && (!defined($DEFAULTVALUE{$var})
991: || $input{$var} ne $DEFAULTVALUE{$var})
992: && $input{$var} ne ""
993: && $var ne 'only_with_tag');
994: }
995: print "<p><label for=\"only_with_tag\" accesskey=\"T\">";
996: print "Show only files with tag:</label>\n";
997: print "<select id=\"only_with_tag\" name=\"only_with_tag\"";
998: print " onchange=\"this.form.submit()\"" if $use_java_script;
999: print ">";
1000: print "<option value=\"\">All tags / default branch</option>\n";
1001:
1002: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
3.136 scop 1003: my $selected =
1004: defined($input{only_with_tag}) && $input{only_with_tag} eq $tag;
1005: printf("<option%s>%s</option>\n",
1006: $selected ? ' selected' : '',
1007: htmlquote($tag));
3.120 scop 1008: }
1009: print "</select>\n";
1010: print " <label for=\"path\" accesskey=\"P\">";
1011: print "Module path or alias:</label>\n";
1012: printf "<input type=\"text\" id=\"path\" name=\"path\" value=\"%s\" size=\"15\">\n", htmlquote($where);
1013: print "<input type=\"submit\" value=\"Go\" accesskey=\"G\"></p>\n";
1014: print "</form>\n";
1015: }
1016:
1017: if ($allow_tar) {
1018: my ($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
1019:
1020: if (defined($basefile) && $basefile ne '') {
1021: print "<hr noshade>\n",
1022: "<div align=\"center\">Download this directory in ";
1023:
1024: # Mangle the filename so browsers show a reasonable
1025: # filename to download.
1026: print
1027: &link("tarball",
1028: "./$basefile.tar.gz$query" . ($query ? "&" : "?") . "tarball=1");
1029: if ($CMD{zip}) {
1030: print " or ",
1031: &link("zip archive",
1032: "./$basefile.zip$query" . ($query ? "&" : "?") . "tarball=1");
1033: }
1034: print "</div>\n";
1035: }
1036: }
1037:
1038: if ($edit_option_form || defined($input{"options"})) {
1039:
1040: my $formwhere = $scriptwhere;
1041: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
1042:
3.149 scop 1043: print <<EOF;
1044: <form method="get" action="${formwhere}">
1045: <input type="hidden" name="copt" value="1">
1046: EOF
3.120 scop 1047: if ($cvstree ne $cvstreedefault) {
1048: print "<input type=\"hidden\" name=\"cvsroot\" value=\"$cvstree\">\n";
1049: }
3.149 scop 1050: print <<EOF;
1051: <center>
1052: <table cellpadding="0" cellspacing="0">
1053: <tr class="dir-header">
1054: <th style="text-align: center">Preferences</th>
1055: </tr>
1056: <tr>
1057: <td>
1058: <label for="sortby" accesskey="F">Sort files by:
1059: <select id="sortby" name="sortby">
1060: <option value="">File</option>
1061: EOF
3.120 scop 1062: print "<option", $bydate ? " selected" : "",
1063: " value=\"date\">Age</option>\n";
1064: print "<option", $byauthor ? " selected" : "",
1065: " value=\"author\">Author</option>\n"
3.140 scop 1066: if $show_author;
3.120 scop 1067: print "<option", $byrev ? " selected" : "",
1068: " value=\"rev\">Revision</option>\n";
1069: print "<option", $bylog ? " selected" : "",
1070: " value=\"log\">Log message</option>\n";
3.140 scop 1071: print "</select></label>,\n";
1072: print '<label for="ignorecase" accesskey="I">case-insensitive: ';
1073: print "<input id=\"ignorecase\" name=\"ignorecase\" type=\"checkbox\"",
1074: $input{'ignorecase'} ? " checked" : "", " value=\"1\"></label>\n";
1075: print "<label for=\"logsort\" accesskey=\"L\">Sort log by: ";
3.120 scop 1076: printLogSortSelect(0);
3.140 scop 1077: print "</label></td>\n</tr>\n";
1078: print "<tr>\n<td><label for=\"f\" accesskey=\"D\">Diff format: ";
3.120 scop 1079: printDiffSelect(0);
3.140 scop 1080: print '</label> ';
1081: print '<label for="hideattic" accesskey="A">Hide files in Attic: ';
3.120 scop 1082: print "<input id=\"hideattic\" name=\"hideattic\" type=\"checkbox\"",
3.149 scop 1083: $input{'hideattic'} ? ' checked' : '',
1084: " value=\"1\"></label></td>\n</tr>\n";
1085: print "<tr>\n<td><label for=\"ln\" accesskey=\"N\">Show line numbers: ";
1086: print "<input id=\"ln\" name=\"ln\" type=\"checkbox\"",
1087: $input{ln} ? ' checked' : '', " value=\"1\"></label></td>\n</tr>\n";
1088: print <<EOF;
1089: <tr>
1090: <td align="center">
1091: <input type="submit" value="Change Options" accesskey="C">
1092: </td>
1093: </tr>
1094: </table>
1095: </center>
1096: </form>
1097: EOF
3.120 scop 1098: }
1099: html_footer();
3.80 knu 1100: }
3.1 knu 1101:
1102: ###############################
1103: # View Files
1104: ###############################
3.80 knu 1105: elsif (-f $fullname . ',v') {
3.114 scop 1106:
3.120 scop 1107: if (forbidden_file($fullname)) {
1108: fatal('403 Forbidden',
1109: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
1110: return;
1111: }
1112:
1113: if (defined($input{'rev'}) || $doCheckout) {
1114: &doCheckout($fullname, $input{'rev'});
1115: gzipclose();
1116: exit;
1117: }
1118:
1119: if (defined($input{'annotate'}) && $allow_annotate) {
1120: &doAnnotate($input{'annotate'});
1121: gzipclose();
1122: exit;
1123: }
1124:
1125: if (defined($input{'r1'}) && defined($input{'r2'})) {
1126: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1127: $input{'r2'}, $input{'tr2'}, $input{'f'});
1128: gzipclose();
1129: exit;
1130: }
3.132 scop 1131:
1132: if (defined($input{'graph'}) && $allow_cvsgraph) {
1133: if (defined($input{'makeimage'})) {
1134: &doGraph($input{'graph'});
1135: } else {
1136: &doGraphView($input{'graph'});
1137: }
1138: gzipclose();
1139: exit;
1140: }
1141:
3.120 scop 1142: &doLog($fullname);
1143:
1144: ##############################
1145: # View Diff
1146: ##############################
1147: } elsif ($fullname =~ s/\.diff$//
1148: && -f $fullname . ",v"
1149: && $input{'r1'}
1150: && $input{'r2'})
1151: {
1152:
1153: # $where-diff-removal if 'cvs rdiff' is used
1154: # .. but 'cvs rdiff'doesn't support some options
1155: # rcsdiff does (-w and -p), so it is disabled
1156: # $where =~ s/\.diff$//;
1157:
1158: # Allow diffs using the ".diff" extension
1159: # so that browsers that default to the URL
1160: # for a save filename don't save diff's as
1161: # e.g. foo.c
1162: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1163: $input{'r2'}, $input{'tr2'}, $input{'f'});
1164: gzipclose();
1165: exit;
1166: } elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1|
1167: && -f $newname . ",v")
1168: {
1169:
1170: # The file has been removed and is in the Attic.
1171: # Send a redirect pointing to the file in the Attic.
1172: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
1173: if ($ENV{QUERY_STRING} ne "") {
1174: redirect("${newplace}?$ENV{QUERY_STRING}");
1175: } else {
1176: redirect($newplace);
1177: }
1178: exit;
3.80 knu 1179: } elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
3.120 scop 1180: http_header("text/plain");
1181: print "You matched the following files:\n";
1182: print join ("\n", @files);
3.80 knu 1183:
3.120 scop 1184: # Find the tags from each file
1185: # Display a form offering diffs between said tags
3.80 knu 1186: } else {
3.120 scop 1187: my $fh = do { local (*FH); };
1188: my ($xtra, $module);
3.80 knu 1189:
3.120 scop 1190: # Assume it's a module name with a potential path following it.
1191: $xtra = (($module = $where) =~ s|/.*||) ? $& : '';
3.80 knu 1192:
3.120 scop 1193: # Is there an indexed version of modules?
1194: if (open($fh, "< $cvsroot/CVSROOT/modules")) {
1195: while (<$fh>) {
1196: if (/^(\S+)\s+(\S+)/o
1197: && $module eq $1
1198: && -d "$cvsroot/$2"
1199: && $module ne $2)
1200: {
1201: redirect("$scriptname/$2$xtra$query");
1202: }
1203: }
1204: }
1205: fatal("404 Not Found", '%s: no such file or directory', $where);
3.80 knu 1206: }
3.23 knu 1207:
3.25 knu 1208: gzipclose();
3.80 knu 1209:
3.1 knu 1210: ## End MAIN
1211:
3.120 scop 1212: sub printDiffSelect($)
1213: {
1214: my ($use_java_script) = @_;
1215: my $f = $input{'f'};
1216:
1217: print '<select id="f" name="f"';
1218: print ' onchange="this.form.submit()"' if $use_java_script;
1219: print ">\n";
1220:
1221: local $_;
1222: for (@DIFFTYPES) {
1223: printf("<option value=\"%s\"%s>%s</option>\n",
1224: $_, $f eq $_ ? ' selected' : '',
1225: "\u$DIFFTYPES{$_}{'descr'}");
1226: }
1227:
1228: print "</select>";
1229: }
1230:
1231: sub printLogSortSelect($)
1232: {
1233: my ($use_java_script) = @_;
1234:
1235: print '<select id="logsort" name="logsort"';
1236: print ' onchange="this.form.submit()"' if $use_java_script;
1237: print ">\n";
1238:
1239: local $_;
1240: for (@LOGSORTKEYS) {
1241: printf("<option value=\"%s\"%s>%s</option>\n",
1242: $_, $logsort eq $_ ? ' selected' : '',
1243: "\u$LOGSORTKEYS{$_}{'descr'}");
1244: }
1245:
1246: print "</select>";
1247: }
1248:
1249: sub findLastModifiedSubdirs(@)
1250: {
1251: my (@dirs) = @_;
1252: my ($dirname, @files);
1253:
1254: foreach $dirname (@dirs) {
1255: next if ($dirname eq ".");
1256: next if ($dirname eq "..");
1257: my ($dir) = "$fullname/$dirname";
1258: next if (!-d $dir);
1259:
1260: my ($lastmod) = undef;
1261: my ($lastmodtime) = undef;
1262: my $dh = do { local (*DH); };
1263:
1264: opendir($dh, $dir) or next;
1265: my (@filenames) = readdir($dh);
1266: closedir($dh);
1267:
1268: foreach my $filename (@filenames) {
1269: $filename = "$dirname/$filename";
1270: my ($file) = "$fullname/$filename";
1271: next if ($filename !~ /,v$/ || !-f $file);
1272:
1273: # Skip forbidden files.
1274: (my $f = $file) =~ s/,v$//;
1275: next if forbidden_file($f);
1276:
1277: $filename =~ s/,v$//;
1278: my $modtime = -M $file;
1279:
1280: if (!defined($lastmod) || $modtime < $lastmodtime) {
1281: $lastmod = $filename;
1282: $lastmodtime = $modtime;
1283: }
1284: }
1285: push (@files, $lastmod) if (defined($lastmod));
1286: }
1287: return @files;
1288: }
1289:
1290: sub htmlify_sub(&$)
1291: {
1292: (my $proc, local $_) = @_;
1293: my @a = split (m`(<a [^>]+>[^<]*</a>)`i);
1294: my $linked;
1295: my $result = '';
1296:
1297: while (($_, $linked) = splice(@a, 0, 2)) {
1298: &$proc();
1299: $result .= $_ if defined($_);
1300: $result .= $linked if defined($linked);
1301: }
1302:
1303: $result;
1304: }
1305:
1306: sub htmlify($;$)
1307: {
1308: (local $_, my $extra) = @_;
1309:
1310: $_ = htmlquote($_);
1311:
1312: # get URL's as link
1313: s{
3.130 scop 1314: ((https?|ftp)://.+?)([\s\']|&(quot|[lg]t);)
3.120 scop 1315: }{
3.130 scop 1316: &link($1, htmlunquote($1)) . $3
3.120 scop 1317: }egx;
1318:
1319: # get e-mails as link
1320: $_ = htmlify_sub {
1321: s<
1322: [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
1323: ><
1324: &link($&, "mailto:$&")
1325: >egix;
1326: } $_;
1327:
1328: if ($extra) {
1329:
1330: # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
1331: if (defined($prcgi) && defined($re_prkeyword)) {
1332: my $prev;
1333:
1334: do {
1335: $prev = $_;
1336:
1337: $_ = htmlify_sub {
1338: s{
1339: (\b$re_prkeyword[:\#]?\s*
1340: (?:
1341: \#?
1342: \d+[,\s]\s*
1343: )*
1344: \#?)
1345: (\d+)\b
1346: }{
1347: $1 . &link($2, sprintf($prcgi, $2))
1348: }egix;
1349: } $_;
1350: } while ($_ ne $prev);
1351:
1352: if (defined($re_prcategories)) {
1353: $_ = htmlify_sub {
1354: s{
1355: (\b$re_prcategories/(\d+)\b)
1356: }{
1357: &link($1, sprintf($prcgi, $2))
1358: }egox;
1359: } $_;
1360: }
1361: }
1362:
1363: # get manpage specs as link: "foo.1" "foo(1)"
1364: if (defined($mancgi)) {
1365: $_ = htmlify_sub {
1366: s{
3.143 knu 1367: (
1368: \b ( \w[\w+\-.]* (?: ::\w[\w+\-.]*)* )
3.120 scop 1369: (?:
3.143 knu 1370: \( ([0-9n]) \) \B
3.120 scop 1371: |
3.143 knu 1372: \. ([0-9n]) \b
3.120 scop 1373: )
1374: )
1375: }{
3.149 scop 1376: my($text, $name, $section) = ($1, $2, defined($3) ? $3 : $4);
1377: ($name =~ /[A-Za-z]/ && $name !~ /\.(:|$)/)
1378: ? &link($text, sprintf($mancgi, $section, $name))
1379: : $text;
3.120 scop 1380: }egx;
1381: } $_;
1382: }
1383: }
1384:
1385: $_;
1386: }
1387:
1388: sub spacedHtmlText($;$)
1389: {
1390: local $_ = $_[0];
1391: my $ts = $_[1] || $tabstop;
1392:
1393: # Cut trailing spaces and tabs
1394: s/[ \t]+$//;
1395:
1396: if (defined($ts)) {
1397:
1398: # Expand tabs
1399: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e;
1400: }
1401:
1402: # replace <tab> and <space> (\001 is to protect us from htmlify)
1403: # gzip can make excellent use of this repeating pattern :-)
1404: if ($hr_breakable) {
1405:
1406: # make every other space 'breakable'
1407: s/ / \001nbsp;/g; # 2 * <space>
1408: # leave single space as it is
1409: } else {
1410: s/ /\001nbsp;/g;
1411: }
1412:
1413: $_ = htmlify($_, $allow_source_extra);
1414:
1415: # unescape
1416: y/\001/&/;
1417:
1418: return $_;
1419: }
1420:
1421: # Note that this doesn't htmlquote the first argument...
1422: sub link($$)
1423: {
1424: my ($name, $url) = @_;
1425:
1426: $url =~ s/:/sprintf("%%%02x", ord($&))/eg
1427: if $url =~ /^[^a-z]/; # relative
1428:
1429: sprintf '<a href="%s">%s</a>', hrefquote($url), $name;
1430: }
1431:
1432: sub revcmp($$)
1433: {
1434: my ($rev1, $rev2) = @_;
1435:
1436: # make no comparison for a tag or a branch
1437: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1438:
1439: my (@r1) = split (/\./, $rev1);
1440: my (@r2) = split (/\./, $rev2);
1441: my ($a, $b);
1442:
1443: while (($a = shift (@r1)) && ($b = shift (@r2))) {
1444: if ($a != $b) {
1445: return $a <=> $b;
1446: }
1447: }
1448: if (@r1) { return 1; }
1449: if (@r2) { return -1; }
1450: return 0;
1451: }
1452:
1453: sub fatal($$@)
1454: {
1455: my ($errcode, $format, @args) = @_;
1456: if ($is_mod_perl) {
1457: Apache->request->status((split (/ /, $errcode))[0]);
1458: } else {
1459: print "Status: $errcode\r\n";
1460: }
3.131 scop 1461: html_header('Error');
3.120 scop 1462: print "<p>Error: ", sprintf($format, map(htmlquote($_), @args)), "</p>\n";
1463: html_footer();
1464: exit(1);
1465: }
1466:
1467: sub redirect($)
1468: {
1469: my ($url) = @_;
1470: if ($is_mod_perl) {
1471: Apache->request->status(301);
1472: Apache->request->header_out(Location => $url);
1473: } else {
1474: print "Status: 301 Moved\r\n";
1475: print "Location: $url\r\n";
1476: }
3.131 scop 1477: html_header('Moved');
3.120 scop 1478: print "<p>This document is located ", &link('here', $url), "</p>\n";
1479: html_footer();
1480: exit(1);
1481: }
1482:
1483: sub safeglob($)
1484: {
1485: my ($filename) = @_;
1486: my ($dirname);
1487: my (@results);
1488: my $dh = do { local (*DH); };
1489:
1490: ($dirname = $filename) =~ s|/[^/]+$||;
1491: $filename =~ s|.*/||;
1492:
1493: if (opendir($dh, $dirname)) {
1494: my $glob = $filename;
1495: my $t;
1496:
3.149 scop 1497: # transform filename from glob to regex. Deal with:
1498: # [, {, ?, * as glob chars
1499: # make sure to escape all other regex chars
3.120 scop 1500: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1501: $glob =~ s/\*/.*/g;
1502: $glob =~ s/\?/./g;
1503: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1504: foreach (readdir($dh)) {
1505:
1506: if (/^${glob}$/) {
1507: push (@results, "$dirname/" . $_);
1508: }
1509: }
1510: closedir($dh);
1511: }
1512:
1513: @results;
1514: }
1515:
3.160 scop 1516:
3.120 scop 1517: sub search_path($)
1518: {
1519: my ($command) = @_;
3.160 scop 1520: for my $d (split (/:/, $command_path)) {
3.120 scop 1521: return "$d/$command" if -x "$d/$command";
1522: }
1523: return '';
1524: }
1525:
3.156 scop 1526:
1527: sub getMimeType($;$)
3.120 scop 1528: {
3.156 scop 1529: my ($fullname, $binary) = @_;
1530: $binary = ($keywordsubstitution && $keywordsubstitution =~ /b/)
1531: unless defined($binary);
1532:
1533: (my $suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1534:
1535: my $mimetype = $MTYPES{$suffix};
1536: $mimetype ||= $MimeTypes->mimeTypeOf($fullname) if defined($MimeTypes);
1537:
1538: if (!$mimetype && $suffix ne '*' && -f $mime_types && -r _) {
1539: my $fh = do { local (*FH); };
1540: if (open($fh, $mime_types)) {
1541: my $re = sprintf('^\s*(\S+\/\S+)\s.+\b%s\b', quotemeta($suffix));
1542: while (my $line = <$fh>) {
1543: if ($line =~ $re) {
1544: $mimetype = $1;
1545: $MTYPES{$suffix} = $mimetype;
1546: last;
1547: }
3.120 scop 1548: }
3.156 scop 1549: close($fh);
1550: } else {
1551: warn("Can't open MIME types file $mime_types for reading: $!");
3.120 scop 1552: }
1553: }
1554:
3.156 scop 1555: $mimetype ||= $MTYPES{'*'};
1556: $mimetype ||= $binary ? 'application/octet-stream' : 'text/plain';
3.120 scop 1557: return $mimetype;
3.1 knu 1558: }
1559:
3.156 scop 1560:
3.1 knu 1561: ###############################
3.24 knu 1562: # read first lines like head(1)
1563: ###############################
3.120 scop 1564: sub head($;$)
1565: {
1566: my $fh = $_[0];
1567: my $linecount = $_[1] || 10;
3.24 knu 1568:
3.120 scop 1569: my @buf;
1570:
1571: if ($linecount > 0) {
1572: my $i;
1573: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1574: push @buf, scalar <$fh>;
1575: }
1576: } else {
1577: @buf = <$fh>;
1578: }
1579:
1580: @buf;
3.24 knu 1581: }
1582:
1583: ###############################
1584: # scan vim and Emacs directives
1585: ###############################
3.120 scop 1586: sub scan_directives(@)
1587: {
1588: my $ts = undef;
3.24 knu 1589:
3.120 scop 1590: for (@_) {
1591: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1592: }
3.24 knu 1593:
3.120 scop 1594: ('tabstop' => $ts);
3.24 knu 1595: }
1596:
3.120 scop 1597: sub openOutputFilter()
1598: {
1599: return if !defined($output_filter) || $output_filter eq '';
3.86 knu 1600:
3.120 scop 1601: open(STDOUT, "|-") and return;
3.86 knu 1602:
3.120 scop 1603: # child of child
1604: open(STDERR, '>/dev/null');
1605: exec($output_filter) or exit -1;
3.86 knu 1606: }
1607:
3.24 knu 1608: ###############################
3.1 knu 1609: # show Annotation
1610: ###############################
3.133 scop 1611: sub doAnnotate($)
3.120 scop 1612: {
1613: my ($rev) = @_;
1614: my ($pid);
1615: my ($pathname, $filename);
1616: my $reader = do { local (*FH); };
1617: my $writer = do { local (*FH); };
1618:
1619: # make sure the revisions are wellformed, for security
1620: # reasons ..
1621: if ($rev =~ /[^\w.]/) {
1622: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1623: }
1624:
1625: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1626: ($filename = $where) =~ s/^.*\///;
1627:
1628: # this seems to be necessary
1629: $| = 1;
1630: $| = 0; # Flush
1631:
3.126 scop 1632: # Work around a mod_perl bug (?) in order to make open2() work.
1633: # Search for "untie STDIN" in mod_perl mailing list archives for more info.
1634: my $old_stdin;
1635: if ($is_mod_perl && ($old_stdin = tied *STDIN)) {
1636: local $^W = undef;
1637: untie *STDIN;
1638: }
1639:
3.120 scop 1640: # this annotate version is based on the
1641: # cvs annotate-demo Perl script by Cyclic Software
1642: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1643: # the public domain.
1644: # we could abandon the use of rlog, rcsdiff and co using
1645: # the cvsserver in a similiar way one day (..after rewrite)
3.128 scop 1646: $pid = open2($reader, $writer, $CMD{cvs}, @annotate_options, 'server')
3.120 scop 1647: or fatal("500 Internal Error",
1648: 'Fatal Error - unable to open cvs for annotation');
3.126 scop 1649:
1650: # Re-tie STDIN if we fiddled around with it earlier, just to be sure.
1651: tie(*STDIN, ref($old_stdin), $old_stdin) if ($old_stdin && !tied(*STDIN));
3.120 scop 1652:
1653: # OK, first send the request to the server. A simplified example is:
1654: # Root /home/kingdon/zwork/cvsroot
1655: # Argument foo/xx
1656: # Directory foo
1657: # /home/kingdon/zwork/cvsroot/foo
1658: # Directory .
1659: # /home/kingdon/zwork/cvsroot
1660: # annotate
1661: # although as you can see there are a few more details.
1662:
1663: print $writer "Root $cvsroot\n";
1664: print $writer
1665: "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1666:
1667: # Don't worry about sending valid-requests, the server just needs to
1668: # support "annotate" and if it doesn't, there isn't anything to be done.
1669: print $writer "UseUnchanged\n";
1670: print $writer "Argument -r\n";
1671: print $writer "Argument $rev\n";
1672: print $writer "Argument $where\n";
1673:
1674: # The protocol requires us to fully fake a working directory (at
1675: # least to the point of including the directories down to the one
1676: # containing the file in question).
3.123 scop 1677: # So if $where is "dir/sdir/file", then dirs will be ("dir","sdir","file")
1678: my $path = '';
1679: foreach my $dir (split('/', $where)) {
3.120 scop 1680:
1681: if ($path eq "") {
3.123 scop 1682: # In our example, $dir is "dir".
1683: $path = $dir;
3.120 scop 1684: } else {
1685: print $writer "Directory $path\n";
1686: print $writer "$cvsroot/$path\n";
1687:
1688: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1689: # And the next time, "file" and "dir/sdir/file" (which then gets
1690: # ignored, because we don't need to send Directory for the file).
3.123 scop 1691: $path .= "/$dir";
3.120 scop 1692: }
1693: }
3.123 scop 1694: undef $path;
3.120 scop 1695:
1696: # And the last "Directory" before "annotate" is the top level.
1697: print $writer "Directory .\n";
1698: print $writer "$cvsroot\n";
1699:
1700: print $writer "annotate\n";
1701:
1702: # OK, we've sent our command to the server. Thing to do is to
1703: # close the writer side and get all the responses. If "cvs server"
1704: # were nicer about buffering, then we could just leave it open, I think.
1705: close($writer) or die "cannot close: $!";
1706:
3.133 scop 1707: navigateHeader($scriptwhere, $pathname, $filename, $rev, 'annotate');
3.120 scop 1708:
3.136 scop 1709: print '<h3 style="text-align: center">Annotation of ',
1710: htmlquote("$pathname$filename"), ", revision $rev</h3>\n";
3.120 scop 1711:
1712: # Ready to get the responses from the server.
1713: # For example:
1714: # E Annotations for foo/xx
1715: # E ***************
1716: # M 1.3 (kingdon 06-Sep-97): hello
1717: # ok
1718: my ($lineNr) = 0;
1719: my ($oldLrev, $oldLusr) = ("", "");
1720: my ($revprint, $usrprint);
1721:
1722: if ($annTable) {
1723: print
1724: "<table style=\"border: none\" cellspacing=\"0\" cellpadding=\"0\">\n";
1725: } else {
1726: print "<pre>";
1727: }
1728:
1729: # prefetch several lines
1730: my @buf = head($reader);
1731:
1732: my %d = scan_directives(@buf);
1733:
1734: while (@buf || !eof($reader)) {
1735: $_ = @buf ? shift @buf : <$reader>;
1736:
1737: my @words = split;
1738:
1739: # Adding one is for the (single) space which follows $words[0].
1740: my $rest = substr($_, length($words[0]) + 1);
1741: if ($words[0] eq "E") {
1742: next;
1743: } elsif ($words[0] eq "M") {
1744: $lineNr++;
1745: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1746: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1747: my $line = substr($_, 36);
1748: my $isCurrentRev = ($rev eq $lrev);
1749:
1750: # we should parse the date here ..
1751: if ($lrev eq $oldLrev) {
1752: $revprint = sprintf('%-8s', '');
1753: } else {
1754: $revprint = sprintf('%-8s', $lrev);
1755: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1756: $oldLusr = '';
1757: }
1758:
1759: if ($lusr eq $oldLusr) {
1760: $usrprint = '';
1761: } else {
1762: $usrprint = $lusr;
1763: }
1764: $oldLrev = $lrev;
1765: $oldLusr = $lusr;
1766:
1767: # Set bold for text-based browsers only - graphical
1768: # browsers show bold fonts a bit wider than regular fonts,
1769: # so it looks irregular.
1770: print "<b>" if ($isCurrentRev && $is_textbased);
1771:
3.136 scop 1772: $usrprint = sprintf('%-8s', $usrprint);
1773: printf '%s%s %s %4d:', $revprint, $isCurrentRev ? '!' : ' ',
1774: htmlquote($usrprint), $lineNr;
3.120 scop 1775: print spacedHtmlText($line, $d{'tabstop'});
1776:
1777: print "</b>" if ($isCurrentRev && $is_textbased);
1778: } elsif ($words[0] eq "ok") {
1779:
1780: # We could complain about any text received after this, like the
1781: # CVS command line client. But for simplicity, we don't.
1782: } elsif ($words[0] eq "error") {
1783: fatal("500 Internal Error",
1784: 'Error occured during annotate: <b>%s</b>', $_);
1785: }
1786: }
1787:
1788: if ($annTable) {
1789: print "</table>";
1790: } else {
1791: print "</pre>";
1792: }
3.124 scop 1793: html_footer();
1794:
3.120 scop 1795: close($reader) or warn "cannot close: $!";
1796: wait;
3.1 knu 1797: }
1798:
1799: ###############################
1800: # make Checkout
1801: ###############################
3.120 scop 1802: sub doCheckout($$)
1803: {
1804: my ($fullname, $rev) = @_;
3.156 scop 1805: my ($revopt);
3.120 scop 1806: my $fh = do { local (*FH); };
1807:
1808: if ($rev eq 'HEAD' || $rev eq '.') {
1809: $rev = undef;
1810: }
1811:
1812: # make sure the revisions a wellformed, for security
1813: # reasons ..
1814: if (defined($rev) && $rev =~ /[^\w.]/) {
1815: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1816: }
1817:
1818: # get mimetype
3.156 scop 1819: my $mimetype;
3.120 scop 1820: if (defined($input{"content-type"})
1821: && ($input{"content-type"} =~ /\S\/\S/))
1822: {
1823: $mimetype = $input{"content-type"};
1824: } else {
3.156 scop 1825: $mimetype = getMimeType($fullname);
3.120 scop 1826: }
1827:
3.163 ! scop 1828: my $moddate = undef;
3.120 scop 1829: if (defined($rev)) {
1830: $revopt = "-r$rev";
1831: if ($use_moddate) {
1832: readLog($fullname, $rev);
1833: $moddate = $date{$rev};
1834: }
1835: } else {
1836: $revopt = "-rHEAD";
1837: if ($use_moddate) {
1838: readLog($fullname);
1839: $moddate = $date{$symrev{HEAD}};
1840: }
1841: }
1842:
1843: ### just for the record:
1844: ### 'cvs co' seems to have a bug regarding single checkout of
1845: ### directories/files having spaces in it;
1846: ### this is an issue that should be resolved on cvs's side
1847: #
1848: # Safely for a child process to read from.
1849: if (!open($fh, "-|")) { # child
1850: # chdir to $tmpdir before to avoid non-readable cgi-bin directories
1851: chdir($tmpdir);
1852: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1853:
1854: # work around a bug of cvs -p; expand symlinks
1855: exec($CMD{cvs}, @cvs_options, '-d', abs_path($cvsroot), 'co', '-p',
1856: $revopt, $where)
1857: or exit -1;
1858: }
1859:
1860: if (eof($fh)) {
1861: fatal("404 Not Found", '%s is not (any longer) pertinent', $where);
1862: }
1863:
1864: #===================================================================
1865: #Checking out squid/src/ftp.c
1866: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1867: #VERS: 1.1.1.28.6.2
1868: #***************
1869:
1870: # Parse CVS header
1871: my ($revision, $filename, $cvsheader);
1872: $filename = "";
1873: while (<$fh>) {
1874: last if (/^\*\*\*\*/);
1875: $revision = $1 if (/^VERS: (.*)$/);
1876:
1877: if (/^Checking out (.*)$/) {
1878: $filename = $1;
1879: $filename =~ s/^\.\/*//;
1880: }
1881: $cvsheader .= $_;
1882: }
1883:
1884: if ($filename ne $where) {
1885: fatal("500 Internal Error",
1886: 'Unexpected output from cvs co: %s', $cvsheader);
1887: }
1888: $| = 1;
1889:
3.146 scop 1890: if ($mimetype =~ $CvsWebMarkupRE) {
3.163 ! scop 1891: # Here we know the last modified date, but don't know if tags have been
! 1892: # added since: no last-modified (for now).
! 1893: cvswebMarkup($fh, $fullname, $revision);
3.120 scop 1894: } else {
3.163 ! scop 1895: http_header($mimetype, $moddate);
3.120 scop 1896: print <$fh>;
1897: }
1898: close($fh);
1.12 fenner 1899: }
1900:
3.163 ! scop 1901: sub cvswebMarkup($$$;$)
3.120 scop 1902: {
3.163 ! scop 1903: my ($filehandle, $fullname, $revision, $mod) = @_;
3.120 scop 1904: my ($pathname, $filename);
3.1 knu 1905:
3.120 scop 1906: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1907: ($filename = $where) =~ s/^.*\///;
3.156 scop 1908: my $fileurl = urlencode($filename);
1909: my $mimetype = getMimeType($filename);
3.120 scop 1910:
3.163 ! scop 1911: navigateHeader($scriptwhere, $pathname, $filename, $revision, 'view', $mod);
3.120 scop 1912:
3.144 scop 1913: print <<EOF;
1914: <hr noshade>
1915: <table width="100%">
1916: <tr>
1917: <td class="log-markup">File:
1918: EOF
3.159 scop 1919: print &clickablePath($where, 1), ' - (';
3.144 scop 1920: &download_link($fileurl, $revision, 'download');
3.156 scop 1921: if ($mimetype ne 'text/plain') {
3.159 scop 1922: print ' / ';
3.120 scop 1923: &download_link($fileurl, $revision, "as text", "text/plain");
1924: }
3.159 scop 1925: print ')';
1926: print ' - ', &graph_link('', $revision, 'graph') if $allow_cvsgraph;
3.120 scop 1927: print "<br>\n";
1928:
1929: if ($show_log_in_markup) {
1930: readLog($fullname); #,$revision);
1931: printLog($revision, 0);
1932: } else {
1933: print "Version: <b>$revision</b><br>\n";
1934: print "Tag: <b>", $input{only_with_tag}, "</b><br>\n"
1935: if $input{only_with_tag};
1936: }
1937: print "</td>\n</tr>\n</table>";
1938: my $url = download_url($fileurl, $revision, $mimetype);
1939: print "<hr noshade>";
1940:
1941: if ($mimetype =~ /^image/) {
3.160 scop 1942: printf '<img src="%s" alt="%s"><br>',
1943: hrefquote("$url$barequery"), htmlquote($filename);
3.120 scop 1944: } elsif ($mimetype =~ m%^application/pdf%) {
3.157 scop 1945: printf '<embed src="%s" width="100%%" height="100%%"><br>',
1946: hrefquote("$url$barequery");
3.120 scop 1947: } elsif ($preformat_in_markup) {
1948: print "<pre>";
1949:
1950: # prefetch several lines
1951: my @buf = head($filehandle);
1952:
1953: my %d = scan_directives(@buf);
1954:
1955: while (@buf || !eof($filehandle)) {
1956: $_ = @buf ? shift @buf : <$filehandle>;
1957:
1958: print spacedHtmlText($_, $d{'tabstop'});
1959: }
1960: print "</pre>";
1961: } else {
1962:
3.148 scop 1963: my $enscript_hl = undef;
1964:
1965: if ($allow_enscript) {
1966: while (my ($hl, $regex) = each %enscript_types) {
3.149 scop 1967: if ($filename =~ $regex) {
1968: $enscript_hl = $hl;
1969: last;
1970: }
3.148 scop 1971: }
1972: }
1973:
3.149 scop 1974: print '<pre>';
1975: my $lineNumber = 0;
1976: my $doLineNumbers = $input{ln} || 0;
1977:
3.148 scop 1978: if ($enscript_hl) {
1979:
1980: my $reader = do { local (*FH); };
1981: my $writer = do { local (*FH); };
1982:
1983: open2($reader, $writer, $CMD{enscript}, @enscript_options,
3.149 scop 1984: qw(-q --language=cvsweb -o -),
1985: "--highlight=$enscript_hl",
1986: '-')
1987: or fatal('500 Internal Error',
1988: 'Fatal Error - unable to open Enscript for colorization');
3.148 scop 1989:
1990: while (<$filehandle>) {
3.149 scop 1991: print $writer $_;
3.148 scop 1992: }
1993: close($writer);
1994: while (<$reader>) {
3.149 scop 1995: if ($doLineNumbers) {
1996: $lineNumber++;
1997: printf '<a id="l%d" class="src">%5d: </a>', ($lineNumber) x 2;
1998: }
3.148 scop 1999: print $_;
2000: }
2001: close($reader);
2002:
2003: } else {
2004: while (<$filehandle>) {
3.149 scop 2005: if ($doLineNumbers) {
2006: $lineNumber++;
2007: printf '<a id="l%d" class="src">%5d: </a>', ($lineNumber) x 2;
2008: }
2009: print htmlquote($_);
3.148 scop 2010: }
3.120 scop 2011: }
3.149 scop 2012:
2013: print "</pre>\n";
3.120 scop 2014: }
3.131 scop 2015: html_footer();
3.120 scop 2016: }
2017:
3.156 scop 2018:
3.120 scop 2019: sub viewable($)
2020: {
3.156 scop 2021: my $mimetype = shift || '';
2022: return ($allow_markup && $mimetype =~ m%^((text|image)/|application/pdf)%);
2023: }
3.120 scop 2024:
3.1 knu 2025:
2026: ###############################
2027: # Show Colored Diff
2028: ###############################
3.120 scop 2029: sub doDiff($$$$$$)
2030: {
2031: my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
2032: my $fh = do { local (*FH); };
2033: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
2034:
2035: if (&forbidden_file($fullname)) {
2036: fatal("403 Forbidden",
2037: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
2038: }
2039:
2040: if ($r1 =~ /([^:]+)(:(.+))?/) {
2041: $rev1 = $1;
2042: $sym1 = $3;
2043: }
2044: if ($r1 eq 'text') {
2045: $rev1 = $tr1;
2046: $sym1 = "";
2047: }
2048:
2049: if ($r2 =~ /([^:]+)(:(.+))?/) {
2050: $rev2 = $1;
2051: $sym2 = $3;
2052: }
2053: if ($r2 eq 'text') {
2054: $rev2 = $tr2;
2055: $sym2 = "";
2056: }
2057:
2058: # make sure the revisions a wellformed, for security
2059: # reasons ..
2060: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
2061: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
2062: }
2063:
2064: #
2065: # rev1 and rev2 are now both numeric revisions.
2066: # Thus we do a DWIM here and swap them if rev1 is after rev2.
2067: # XXX should we warn about the fact that we do this?
2068: if (&revcmp($rev1, $rev2) > 0) {
2069: my ($tmp1, $tmp2) = ($rev1, $sym1);
2070: ($rev1, $sym1) = ($rev2, $sym2);
2071: ($rev2, $sym2) = ($tmp1, $tmp2);
2072: }
2073: my $difftype = $DIFFTYPES{$f};
2074:
2075: if (!$difftype) {
2076: fatal("400 Bad arguments", 'Diff format %s not understood', $f);
2077: }
2078:
2079: my @difftype = @{$difftype->{'opts'}};
2080: my $human_readable = $difftype->{'colored'};
2081:
2082: # apply special options
2083: if ($showfunc) {
2084: push @difftype, '-p' if $f ne 's';
2085:
2086: my ($re1, $re2);
2087:
2088: while (($re1, $re2) = each %funcline_regexp) {
2089: if ($fullname =~ /$re1/) {
2090: push @difftype, '-F', $re2;
2091: last;
2092: }
2093: }
2094: }
2095:
2096: if ($human_readable) {
2097: if ($hr_ignwhite) {
2098: push @difftype, '-w';
2099: }
2100: if ($hr_ignkeysubst) {
2101: push @difftype, '-kk';
2102: }
2103: }
2104:
2105: if (!open($fh, "-|")) { # child
2106: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
2107: openOutputFilter();
2108: exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname) or exit -1;
2109: }
2110: if ($human_readable) {
2111: &human_readable_diff($fh, $rev2);
2112: html_footer();
2113: gzipclose();
2114: exit;
2115: } else {
2116: http_header("text/plain");
2117: }
2118:
2119: #
2120: #===================================================================
2121: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
2122: #retrieving revision 1.16
2123: #retrieving revision 1.17
2124: #diff -c -r1.16 -r1.17
2125: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2126: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
2127: #
2128: # Ideas:
2129: # - nuke the stderr output if it's what we expect it to be
2130: # - Add "no differences found" if the diff command supplied no output.
2131: #
2132: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2133: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
2134: # (bogus example, but...)
2135: #
2136: if (grep { $_ eq '-u' } @difftype) {
2137: $f1 = '---';
2138: $f2 = '\+\+\+';
2139: } else {
2140: $f1 = '\*\*\*';
2141: $f2 = '---';
2142: }
2143:
2144: while (<$fh>) {
2145: if (m|^$f1 $cvsroot|o) {
2146: s|$cvsroot/||o;
2147: if ($sym1) {
2148: chop;
2149: $_ .= " $sym1\n";
2150: }
2151: } elsif (m|^$f2 $cvsroot|o) {
2152: s|$cvsroot/||o;
2153:
2154: if ($sym2) {
2155: chop;
2156: $_ .= " $sym2\n";
2157: }
2158: }
2159: print $_;
2160: }
2161: close($fh);
1.12 fenner 2162: }
2163:
3.1 knu 2164: ###############################
2165: # Show Logs ..
2166: ###############################
3.120 scop 2167: sub getDirLogs($$@)
2168: {
2169: my ($cvsroot, $dirname, @otherFiles) = @_;
3.139 scop 2170: my $tag = $input{only_with_tag};
2171: my $DirName = "$cvsroot/$where";
3.120 scop 2172:
3.139 scop 2173: my @files = &safeglob("$DirName/*,v");
2174: push (@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
3.120 scop 2175: foreach my $file (@otherFiles) {
2176: push (@files, "$DirName/$file");
2177: }
2178:
3.150 scop 2179: # Weed out unreadable files.
2180: my $i = 0;
2181: my @unreadable = ();
2182: while ($i < scalar(@files)) {
2183: if (-r $files[$i]) {
2184: $i++;
2185: } else {
2186: push(@unreadable, splice(@files, $i, 1));
2187: }
2188: }
2189:
3.139 scop 2190: # If there are no files, we're done.
3.150 scop 2191: return @unreadable unless @files;
3.120 scop 2192:
3.139 scop 2193: my @cmd = ($CMD{rlog});
2194: # Can't use -r<tag> as '-' is allowed in tagnames,
2195: # but misinterpreted by rlog.
2196: push(@cmd, '-r') unless defined($tag);
3.120 scop 2197:
3.139 scop 2198: my $fh = do { local (*FH); };
2199: if (!open($fh, '-|')) { # Child
2200: open(STDERR, '>/dev/null'); # Ignore rlog's complaints.
2201: openOutputFilter();
2202: if ($file_list_len && $file_list_len > 1) {
2203: while (scalar(@files) > $file_list_len) { # Process files in chunks.
2204: system(@cmd, splice(@files, 0, $file_list_len)) == 0 or exit -1;
2205: }
3.120 scop 2206: }
3.139 scop 2207: exec(@cmd, @files) or exit -1;
2208: }
2209: undef @cmd;
3.120 scop 2210:
3.139 scop 2211: my $state = 'start';
2212: my ($date, $branchpoint, $branch, $log, @filetags);
3.152 scop 2213: my ($rev, $revision, $revwanted, $filename, $head, $author, $keywordsubst);
3.120 scop 2214:
2215: while (<$fh>) {
2216: if ($state eq "start") {
2217:
2218: #Next file. Initialize file variables
2219: $rev = '';
2220: $revwanted = '';
2221: $branch = '';
2222: $branchpoint = '';
2223: $filename = '';
2224: $log = '';
2225: $revision = '';
2226: %symrev = ();
2227: @filetags = ();
3.152 scop 2228: $keywordsubst= '';
3.120 scop 2229:
2230: #jump to head state
2231: $state = "head";
2232: }
3.144 scop 2233:
3.120 scop 2234: again:
2235:
2236: if ($state eq "head") {
2237:
2238: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
2239:
2240: if (/^Working file: (.+)$/) {
2241: $filename = $1;
2242: } elsif (/^head: (.+)$/) {
2243: $head = $1;
2244: } elsif (/^branch: (.+)$/) {
2245: $branch = $1;
3.152 scop 2246: } elsif (/^keyword substitution: (.+)$/) {
2247: $keywordsubst = $1;
3.120 scop 2248: } elsif (/^symbolic names:/) {
2249: $state = "tags";
2250: ($branch = $head) =~ s/\.\d+$//
2251: if $branch eq '';
2252: $branch =~ s/(\d+)$/0.$1/;
2253: $symrev{MAIN} = $branch;
2254: $symrev{HEAD} = $branch;
2255: $alltags{MAIN} = 1;
2256: $alltags{HEAD} = 1;
2257: push (@filetags, "MAIN", "HEAD");
2258: } elsif (/$LOG_REVSEPARATOR/o) {
2259: $state = "log";
2260: $rev = '';
2261: $date = '';
2262: $log = '';
2263:
2264: # Try to reconstruct the relative filename if RCS spits out a full path
2265: $filename =~ s%^\Q$DirName\E/%%;
2266: }
2267: next;
2268: }
2269:
2270: if ($state eq "tags") {
2271: if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
2272: push (@filetags, $1);
2273: $symrev{$1} = $2;
2274: $alltags{$1} = 1;
2275: next;
2276: } elsif (/^\S/) {
2277:
2278: if (defined($tag)) {
2279: if (defined($symrev{$tag}) || $tag eq "HEAD") {
2280: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
2281: ($branch = $revwanted) =~ s/\b0\.//;
2282: ($branchpoint = $branch) =~ s/\.?\d+$//;
2283: $revwanted = '' if ($revwanted ne $branch);
2284: } elsif ($tag ne "HEAD") {
2285: $state = "skip";
2286: next;
2287: }
2288: }
2289:
2290: foreach my $tagfound (@filetags) {
2291: $tags{$tagfound} = 1;
2292: }
2293: $state = "head";
2294: goto again;
2295: }
2296: }
2297:
2298: if ($state eq "log") {
2299: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
2300:
2301: # End of a log entry.
2302: my $revbranch = $rev;
2303: $revbranch =~ s/\.\d+$//;
2304:
2305: if ($revwanted eq '' && $branch ne '' && $branch eq $revbranch
2306: || !defined($tag))
2307: {
2308: $revwanted = $rev;
2309: }
2310:
2311: if ($revwanted ne ''
2312: ? $rev eq $revwanted
2313: : $branchpoint ne ''
2314: ? $rev eq $branchpoint
2315: : 0
2316: && ($rev eq $head))
2317: { # Don't think head is needed here..
3.152 scop 2318: my @finfo = ($rev, $date, $log, $author, $filename, $keywordsubst);
2319: (my $name = $filename) =~ s%/.*%%;
3.120 scop 2320: $fileinfo{$name} = [@finfo];
2321: $state = "done" if ($rev eq $revwanted);
2322: }
2323: $rev = '';
2324: $date = '';
2325: $log = '';
2326: } elsif ($date eq ''
2327: && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|)
2328: {
2329: my $yr = $1;
2330:
2331: # damn 2-digit year routines :-)
2332: if ($yr > 100) {
2333: $yr -= 1900;
2334: }
2335: $date = &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
2336: ($author) = /author: ([^;]+)/;
2337: $state = "log";
2338: $log = '';
2339: next;
2340: } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
2341: $rev = $1; # .*$ eats up the locker(lockers?) info, if any
2342: next;
2343: } else {
2344: $log .= $_;
2345: }
2346: }
2347:
2348: if (/$LOG_FILESEPARATOR/o) {
2349: $state = "start";
2350: next;
2351: }
2352: }
2353:
3.139 scop 2354: my $linesread = $. || 0;
2355: close($fh);
2356:
2357: if ($linesread == 0) {
3.137 scop 2358: fatal('500 Internal Error',
2359: 'Failed to spawn GNU rlog on <em>"%s"</em>.<br><br>Did you set the <b><code>$command_path</code></b> in your configuration file correctly? (Currently: "<code>%s</code>")',
3.150 scop 2360: htmlquote(join(', ', @files)), $command_path);
3.120 scop 2361: }
3.150 scop 2362:
2363: return @unreadable;
3.120 scop 2364: }
2365:
2366: sub readLog($;$)
2367: {
2368: my ($fullname, $revision) = @_;
2369: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2370: my $fh = do { local (*FH); };
2371:
3.144 scop 2372: $revision = defined($revision) ? "-r$revision" : '';
3.120 scop 2373:
2374: undef %symrev;
2375: undef %revsym;
2376: undef @allrevisions;
2377: undef %date;
2378: undef %author;
2379: undef %state;
2380: undef %difflines;
2381: undef %log;
3.152 scop 2382: $keywordsubstitution = '';
3.120 scop 2383:
2384: if (!open($fh, "-|")) { # child
2385: if ($revision ne '') {
2386: openOutputFilter();
2387: exec($CMD{rlog}, $revision, $fullname) or exit -1;
2388: } else {
2389: openOutputFilter();
2390: exec($CMD{rlog}, $fullname) or exit -1;
2391: }
2392: }
2393:
2394: while (<$fh>) {
2395: if ($symnames) {
2396: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2397: $symrev{$1} = $2;
3.152 scop 2398: next;
3.120 scop 2399: } else {
2400: $symnames = 0;
2401: }
3.152 scop 2402: }
2403: if (/^head:\s+([\d\.]+)/) {
3.120 scop 2404: $head = $1;
2405: } elsif (/^branch:\s+([\d\.]+)/) {
2406: $curbranch = $1;
2407: } elsif (/^symbolic names/) {
2408: $symnames = 1;
3.152 scop 2409: } elsif (/^keyword substitution: (.+)$/) {
2410: $keywordsubstitution = $1;
3.120 scop 2411: } elsif (/^-----/) {
2412: last;
2413: }
2414: }
2415: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
2416:
2417: # each log entry is of the form:
2418: # ----------------------------
2419: # revision 3.7.1.1
2420: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2421: # log info
2422: # ----------------------------
2423:
2424: # For a locked revision, the first line after the separator
2425: # becomes smth like
3.149 scop 2426: # revision 9.19 locked by: vassilii;
3.120 scop 2427:
2428: logentry:
2429:
2430: while (!/$LOG_FILESEPARATOR/o) {
2431: $_ = <$fh>;
2432: last logentry if (!defined($_)); # EOF
2433: if (/^revision (\d+(?:\.\d+)+)/) {
2434: $rev = $1;
2435: unshift (@allrevisions, $rev);
2436: } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
2437: next logentry;
2438: } else {
2439:
2440: # The rlog output is syntactically ambiguous. We must
2441: # have guessed wrong about where the end of the last log
2442: # message was.
2443: # Since this is likely to happen when people put rlog output
2444: # in their commit messages, don't even bother keeping
2445: # these lines since we don't know what revision they go with
2446: # any more.
2447: next logentry;
2448: }
2449: $_ = <$fh>;
2450: if (
2451: m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
2452: )
2453: {
2454: my $yr = $1;
2455:
2456: # damn 2-digit year routines :-)
2457: if ($yr > 100) {
2458: $yr -= 1900;
2459: }
2460: $date{$rev} = &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
2461: $author{$rev} = $7;
2462: $state{$rev} = $8;
2463: $difflines{$rev} = $10;
2464: } else {
2465: fatal("500 Internal Error", 'Error parsing RCS output: %s', $_);
2466: }
2467:
2468: line:
2469: while (<$fh>) {
2470: next line if (/^branches:\s/);
2471: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
2472: $log{$rev} .= $_;
2473: }
2474: }
2475: close($fh);
2476:
2477: @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
2478:
2479: #
2480: # HEAD is an artificial tag which is simply the highest tag number on the main
2481: # branch, unless there is a branch tag in the RCS file in which case it's the
2482: # highest revision on that branch. Find it by looking through @revorder; it
2483: # is the first commit listed on the appropriate branch.
2484: # This is not neccesary the same revision as marked as head in the RCS file.
2485: my $headrev = $curbranch || "1";
2486: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
2487:
2488: foreach $rev (@revorder) {
2489: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2490: $symrev{"HEAD"} = $rev;
2491: last;
2492: }
2493: }
2494: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2495: if (!defined($symrev{"HEAD"}));
2496:
2497: #
2498: # Now that we know all of the revision numbers, we can associate
2499: # absolute revision numbers with all of the symbolic names, and
2500: # pass them to the form so that the same association doesn't have
2501: # to be built then.
2502: #
2503: undef @branchnames;
2504: undef %branchpoint;
2505: undef $sel;
2506:
2507: foreach (reverse sort keys %symrev) {
2508: $rev = $symrev{$_};
2509: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
2510: push (@branchnames, $_);
2511:
2512: #
2513: # A revision number of A.B.0.D really translates into
2514: # "the highest current revision on branch A.B.D".
2515: #
2516: # If there is no branch A.B.D, then it translates into
2517: # the head A.B .
2518: #
2519: # This reasoning also applies to the main branch A.B,
2520: # with the branch number 0.A, with the exception that
2521: # it has no head to translate to if there is nothing on
2522: # the branch, but I guess this can never happen?
2523: #
2524: # (the code below gracefully forgets about the branch
2525: # if it should happen)
2526: #
2527: $head = defined($2) ? $2 : "";
2528: $branch = $3;
2529: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2530: my $regex;
2531: $regex = quotemeta $branchrev;
2532: $rev = $head;
2533:
2534: foreach my $r (@revorder) {
2535: if ($r =~ /^${regex}\b/) {
2536: $rev = $branchrev;
2537: last;
2538: }
2539: }
2540: next if ($rev eq "");
2541:
2542: if ($rev ne $head && $head ne "") {
3.131 scop 2543: $branchpoint{$head} .= ', ' if ($branchpoint{$head});
3.120 scop 2544: $branchpoint{$head} .= $_;
2545: }
2546: }
2547: $revsym{$rev} .= ", " if ($revsym{$rev});
2548: $revsym{$rev} .= $_;
3.136 scop 2549: $sel .= sprintf("<option value=\"%s:%s\">%s</option>\n",
2550: htmlquote($rev), (htmlquote($_)) x 2);
3.120 scop 2551: }
2552:
2553: my ($onlyonbranch, $onlybranchpoint);
2554: if ($onlyonbranch = $input{'only_with_tag'}) {
2555: $onlyonbranch = $symrev{$onlyonbranch};
2556: if ($onlyonbranch =~ s/\b0\.//) {
2557: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2558: } else {
2559: $onlybranchpoint = $onlyonbranch;
2560: }
2561:
2562: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2563: fatal("404 Tag not found", 'Tag %s not defined',
3.131 scop 2564: $input{'only_with_tag'});
3.120 scop 2565: }
2566: }
2567:
2568: undef @revisions;
2569:
2570: foreach (@allrevisions) {
2571: ($br = $_) =~ s/\.\d+$//;
2572: ($brp = $br) =~ s/\.\d+$//;
2573: next if ($onlyonbranch
2574: && $br ne $onlyonbranch
2575: && $_ ne $onlybranchpoint);
2576: unshift (@revisions, $_);
2577: }
2578:
2579: if ($logsort eq "date") {
2580:
2581: # Sort the revisions in commit order an secondary sort on revision
2582: # (secondary sort needed for imported sources, or the first main
2583: # revision gets before the same revision on the 1.1.1 branch)
2584: @revdisplayorder =
2585: sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) } @revisions;
2586: } elsif ($logsort eq "rev") {
2587:
2588: # Sort the revisions in revision order, highest first
2589: @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
2590: } else {
2591:
2592: # No sorting. Present in the same order as rlog / cvs log
2593: @revdisplayorder = @revisions;
2594: }
2595:
2596: }
2597:
2598: sub printDiffLinks($$)
2599: {
2600: my ($text, $url) = @_;
2601: my @extra;
2602:
2603: local $_;
2604: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2605: my $f = $_ eq $defaultDiffType ? '' : $_;
2606:
2607: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2608: }
2609:
2610: print &link($text, $url), ' (', join (', ', @extra), ')';
2611: }
2612:
2613: sub printLog($;$)
2614: {
2615: my ($link, $br, $brp);
2616: ($_, $link) = @_;
2617: ($br = $_) =~ s/\.\d+$//;
2618: ($brp = $br) =~ s/\.?\d+$//;
3.131 scop 2619: my $prev;
3.120 scop 2620:
2621: $link = 1 if (!defined($link));
3.131 scop 2622: my $isDead = ($state{$_} eq 'dead');
2623: my $isSelected = (defined($input{'r1'}) && $input{'r1'} eq $_);
3.120 scop 2624:
3.131 scop 2625: print "<div class=\"diff-selected\">\n" if $isSelected;
3.120 scop 2626: print "<p>\n";
3.131 scop 2627:
3.120 scop 2628: if ($link && !$isDead) {
3.156 scop 2629: (my $filename = $where) =~ s/^.*\///;
2630: my $fileurl = urlencode($filename);
2631: my $mimetype = getMimeType($filename);
2632: my $viewable = viewable($mimetype);
2633:
3.120 scop 2634: print "<a name=\"rev$_\"></a>";
2635:
2636: if (defined($revsym{$_})) {
2637: foreach my $sym (split (", ", $revsym{$_})) {
3.136 scop 2638: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2639: }
2640: }
2641:
2642: if (defined($revsym{$br})
2643: && $revsym{$br}
2644: && !defined($nameprinted{$br}))
2645: {
2646: foreach my $sym (split (", ", $revsym{$br})) {
3.136 scop 2647: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2648: }
2649: $nameprinted{$br} = 1;
2650: }
2651: print "\n Revision ";
2652: &download_link($fileurl, $_, $_,
3.156 scop 2653: $viewable ? 'text/x-cvsweb-markup' : undef);
3.120 scop 2654:
3.161 scop 2655: print ' / (';
2656:
3.156 scop 2657: if ($viewable) {
3.120 scop 2658: &download_link($fileurl, $_, "download", $mimetype);
2659: }
2660:
3.156 scop 2661: if ($mimetype ne 'text/plain') {
3.161 scop 2662: print ' / ' if $viewable;
3.120 scop 2663: &download_link($fileurl, $_, "as text", "text/plain");
2664: }
2665:
3.156 scop 2666: if (!$viewable) {
3.161 scop 2667: print ' / ' if ($mimetype ne 'text/plain');
3.120 scop 2668: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2669: }
3.161 scop 2670:
2671: print ')';
3.120 scop 2672:
2673: if ($allow_annotate) {
2674: print " - ";
2675: print &link('annotate',
2676: sprintf('%s/%s?annotate=%s%s',
2677: $scriptname, urlencode($where), $_, $barequery));
2678: }
2679:
2680: # Plus a select link if enabled, and this version isn't selected
2681: if ($allow_version_select) {
3.131 scop 2682: print ' - ';
2683: if ($isSelected) {
2684: print '<b>[selected]</b>';
3.120 scop 2685: } else {
3.159 scop 2686: print &link('select for diffs',
3.131 scop 2687: sprintf('%s?r1=%s%s#rev%s',
2688: $scriptwhere, $_, $barequery, $_));
3.120 scop 2689: }
2690: }
2691: } else {
2692: print "Revision <b>$_</b>";
2693: }
2694:
2695: if (/^1\.1\.1\.\d+$/) {
2696: print " <i>(vendor branch)</i>";
2697: }
2698: if (defined @mytz) {
2699: my ($est) = $mytz[(localtime($date{$_}))[8]];
2700: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
2701: } else {
2702: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
2703: }
3.136 scop 2704: print readableTime(time() - $date{$_}, 1), ' ago)';
2705: print ' by <i>', htmlquote($author{$_}), "</i>\n";
2706:
2707: if ($revsym{$br}) {
2708: printf "<br>Branch: <b>%s</b>\n",
2709: $link ? link_tags($revsym{$br}) : htmlquote($revsym{$br});
2710: }
2711: if ($revsym{$_}) {
2712: printf "<br>CVS Tags: <b>%s</b>\n",
2713: $link ? link_tags($revsym{$_}) : htmlquote($revsym{$_});
2714: }
2715: if ($branchpoint{$_}) {
2716: printf "<br>Branch point for: <b>%s</b>\n",
2717: $link ? link_tags($branchpoint{$_}) : htmlquote($branchpoint{$_});
2718: }
3.120 scop 2719:
2720: # Find the previous revision
2721: my @prevrev = split (/\./, $_);
2722: do {
2723: if (--$prevrev[$#prevrev] <= 0) {
2724:
2725: # If it was X.Y.Z.1, just make it X.Y
2726: pop (@prevrev);
2727: pop (@prevrev);
2728: }
2729: $prev = join (".", @prevrev);
2730: } until (defined($date{$prev}) || $prev eq "");
2731:
2732: if ($prev ne "") {
2733: if ($difflines{$_}) {
2734: print "<br>Changes since <b>$prev: $difflines{$_} lines</b>";
2735: }
2736: }
2737:
2738: if ($isDead) {
2739: print "<br><b><i>FILE REMOVED</i></b>\n";
2740: } elsif ($link) {
2741: my %diffrev = ();
2742: $diffrev{$_} = 1;
2743: $diffrev{""} = 1;
2744: print '<br>';
2745: my $diff = 'Diff';
2746:
2747: #
2748: # Offer diff to previous revision
2749: if ($prev) {
2750: $diffrev{$prev} = 1;
2751:
2752: my $url =
2753: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $prev, $_, $barequery);
2754:
2755: print $diff, " to previous ";
2756: $diff = '';
2757: printDiffLinks($prev, $url);
2758: }
2759:
2760: #
2761: # Plus, if it's on a branch, and it's not a vendor branch,
2762: # offer a diff with the branch point.
2763: if ($revsym{$brp}
2764: && !/^1\.1\.1\.\d+$/
2765: && !defined($diffrev{$brp}))
2766: {
2767: my $url =
2768: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp, $_, $barequery);
2769:
2770: print $diff, " to branchpoint ";
2771: $diff = '';
2772: printDiffLinks($brp, $url);
2773: }
2774:
2775: #
2776: # Plus, if it's on a branch, and it's not a vendor branch,
2777: # offer to diff with the next revision of the higher branch.
2778: # (e.g. change gets committed and then brought
2779: # over to -stable)
2780: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2781: my ($i, $nextmain);
2782:
2783: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++) {
2784: }
2785: my @tmp2 = split (/\./, $_);
2786: for ($nextmain = ""; $i > 0; $i--) {
2787: my $next = $revorder[$i - 1];
2788: my @tmp1 = split (/\./, $next);
2789:
2790: if (@tmp1 < @tmp2) {
2791: $nextmain = $next;
2792: last;
2793: }
2794:
2795: # Only the highest version on a branch should have
2796: # a diff for the "next main".
2797: last
2798: if (@tmp1 - 1 <= @tmp2
2799: && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
2800: join (".", @tmp2[0 .. $#tmp1 - 1]));
2801: }
2802:
2803: if (!defined($diffrev{$nextmain})) {
2804: $diffrev{$nextmain} = 1;
2805:
2806: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2807: $scriptwhere, $nextmain, $_, $barequery);
2808:
2809: print $diff, " next main ";
2810: $diff = '';
2811: printDiffLinks($nextmain, $url);
2812: }
2813: }
2814:
2815: # Plus if user has selected only r1, then present a link
2816: # to make a diff to that revision
2817: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2818: $diffrev{$input{"r1"}} = 1;
2819:
2820: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2821: $scriptwhere, $input{'r1'}, $_, $barequery);
2822:
2823: print $diff, " to selected ";
2824: $diff = '';
2825: printDiffLinks($input{'r1'}, $url);
2826: }
2827:
2828: }
2829: print "\n</p>\n<pre>\n";
2830: print &htmlify($log{$_}, $allow_log_extra);
2831: print "</pre>\n";
3.131 scop 2832: print "</div>\n" if $isSelected;
3.120 scop 2833: }
2834:
3.132 scop 2835: #
2836: # Generates the HTML view for CvsGraph.
2837: #
2838: sub doGraphView($)
2839: {
2840: my ($rev) = @_;
2841:
2842: (my $pathname = $where) =~ s|[^/]*$||;
2843: (my $filename = $where) =~ s|^.*/||;
2844:
2845: navigateHeader($scriptwhere, $pathname, $filename, $rev, 'graph');
2846:
3.146 scop 2847: my $title = 'Revision graph of ' . htmlquote($pathname . $filename);
3.132 scop 2848: my $mapname = 'CvsGraphMap';
3.156 scop 2849: my $ctype = viewable(getMimeType($filename)) ?
2850: '&content-type=text/x-cvsweb-markup' : '';
3.132 scop 2851:
3.151 scop 2852: printf(<<EOF, $title, $mapname, $cvstree, $rev, $title);
3.146 scop 2853: <h3 style="text-align: center">%s</h3>
3.151 scop 2854: <div align="center"><img border="0" usemap="#%s" src="?cvsroot=%s&graph=%s&makeimage=1" alt="%s"></div>
3.146 scop 2855: EOF
3.132 scop 2856:
3.135 scop 2857: my @graph_cmd =
2858: ($CMD{cvsgraph},
2859: '-r', $cvsroot,
2860: '-i',
2861: '-M', $mapname,
3.146 scop 2862: '-x', 4,
2863: "-Omap_branch_href=\"href=\\\"./?only_with_tag=%(%t%)$barequery\\\"\"",
2864: "-Omap_rev_href=\"href=\\\"?rev=%(%R%)$barequery$ctype\\\"\"",
2865: "-Omap_diff_href=\"href=\\\"%(%F%).diff" .
2866: "?r1=%(%P%)&r2=%(%R%)$barequery\\\"\"",
3.135 scop 2867: );
3.132 scop 2868: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
2869:
2870: my $pipe = IO::Pipe->new();
2871: $pipe->reader(@graph_cmd, $pathname . $filename . ',v');
2872: while (<$pipe>) {
2873: print;
2874: }
2875: $pipe = undef;
2876:
2877: html_footer();
2878: }
2879:
2880: #
2881: # Generates a graph using CvsGraph.
2882: #
2883: sub doGraph($)
2884: {
2885: my ($rev) = @_;
2886:
2887: (my $pathname = $where) =~ s|[^/]*$||;
2888: (my $filename = $where) =~ s|^.*/||;
2889:
2890: http_header('image/png');
2891:
2892: my @graph_cmd = ($CMD{cvsgraph}, '-r', $cvsroot);
2893: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
2894:
2895: my $pipe = IO::Pipe->new();
2896: $pipe->reader(@graph_cmd, $pathname . $filename . ',v');
2897: {
2898: local $/ = undef;
2899: binmode(\*STDOUT);
2900: print <$pipe>;
2901: }
2902: $pipe = undef;
2903: }
2904:
2905:
3.120 scop 2906: sub doLog($)
2907: {
2908: my ($fullname) = @_;
2909:
2910: readLog($fullname);
2911:
2912: html_header("CVS log for $where");
3.144 scop 2913:
2914: (my $upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2915: (my $filename = $where) =~ s|^.*/||;
2916: my $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2917:
3.120 scop 2918: print "<p>\n ";
2919: print &link($backicon, "$backurl#$filename"), " <b>Up to ",
2920: &clickablePath($upwhere, 1), "</b>\n</p>\n";
2921: print "<p>\n ";
2922: print &link('Request diff between arbitrary revisions', '#diff');
3.132 scop 2923: if ($allow_cvsgraph) {
2924: print ' / ', &graph_link('', 1, 'Display revisions graphically');
2925: }
3.120 scop 2926: print "\n</p>\n<hr noshade>\n";
2927:
2928: print "<p>\n";
3.152 scop 2929:
2930: my $explain = $keywordsubstitution =~ /b/ ?
2931: ' (i.e.: CVS considers this a binary file)' : '';
2932: print "Keyword substitution: $keywordsubstitution$explain<br>\n";
3.144 scop 2933: print $curbranch
2934: ? ("Default branch: ", ($revsym{$curbranch} || $curbranch))
2935: : "No default branch";
3.120 scop 2936: print "<br>\n";
2937:
3.153 scop 2938: print 'Current tag: ', htmlquote($input{only_with_tag}), "<br>\n"
2939: if $input{only_with_tag};
3.120 scop 2940: print "</p>\n";
2941:
2942: undef %nameprinted;
2943:
2944: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2945: print "<hr size=\"1\" noshade>\n";
2946: printLog($revdisplayorder[$i]);
2947: }
2948:
3.144 scop 2949: printf(<<EOF, $scriptwhere);
2950: <hr noshade>
2951: <p>
2952: <a name="diff">
2953: This form allows you to request diff's between any two revisions of a file.
2954: You may select a symbolic revision name using the selection box or you may
2955: type in a numeric name using the type-in text box.
2956: </a>
2957: </p>
2958: <form method="get" action="%s.diff" name="diff_select">
2959: EOF
3.120 scop 2960:
2961: foreach (@stickyvars) {
3.154 scop 2962: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\">\n",
2963: $_, htmlquote($input{$_}))
3.120 scop 2964: if (defined($input{$_})
2965: && ((!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_})
2966: && $input{$_} ne ""));
2967: }
3.144 scop 2968:
2969: print <<EOF;
2970: <table style="border: none">
2971: <tr>
2972: <td align="right">
2973: <label for="r1" accesskey="1">Diffs between </label>
2974: <select id="r1" name="r1">
2975: <option value="text" selected>Use Text Field</option>
2976: EOF
2977: print $sel, "</select>\n";
2978:
2979: my $diffrev = defined($input{r1}) ?
2980: $input{r1} : $revdisplayorder[$#revdisplayorder];
2981:
2982: printf(<<EOF, $inputTextSize, $diffrev);
3.147 scop 2983: <input type="text" size="%s" name="tr1" value="%s" onchange="this.form.r1.selectedIndex=0">
3.144 scop 2984: </td>
2985: <td><br></td>
2986: </tr><tr>
2987: <td align="right">
2988: <label for="r2" accesskey="2">and </label>
2989: <select id="r2" name="r2">
2990: <option value="text" selected>Use Text Field</option>
2991: EOF
2992: print $sel, "</select>\n";
2993:
2994: $diffrev = defined($input{r2}) ? $input{r2} : $revdisplayorder[0];
2995:
2996: printf(<<EOF, $inputTextSize, $diffrev, $scriptwhere);
2997: <input type="text" size="%s" name="tr2" value="%s" onchange="this.form.r2.selectedIndex=0">
2998: </td>
2999: <td><input type="submit" value=" Get Diffs " accesskey="G"></td>
3000: </tr>
3001: </table>
3002: </form>
3003: <hr noshade>
3004: <form method="get" action="%s">
3005: <table style="border: none">
3006: <tr>
3007: <td align="right">
3008: <label for="f" accesskey="D">Preferred Diff type:</label>
3009: </td><td>
3010: EOF
3011:
3.120 scop 3012: printDiffSelect($use_java_script);
3.144 scop 3013:
3014: print <<EOF;
3015: </td>
3016: <td></td>
3017: </tr>
3018: EOF
3.120 scop 3019:
3020: if (@branchnames) {
3.144 scop 3021:
3022: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3023: <tr>
3024: <td align="right">
3025: <label for="only_with_tag" accesskey="B">View only Branch:</label>
3026: </td><td>
3027: <a name="branch"></a>
3028: <select id="only_with_tag" name="only_with_tag"%s>
3029: EOF
3030: print '<option value=""';
3031: print ' selected'
3032: if (defined($input{"only_with_tag"}) && $input{"only_with_tag"} eq '');
3.120 scop 3033: print ">Show all branches</option>\n";
3034:
3035: foreach (reverse sort @branchnames) {
3.136 scop 3036: my $selected =
3037: (defined($input{"only_with_tag"}) && $input{"only_with_tag"} eq $_);
3038: printf("<option%s>%s</option>\n",
3039: $selected ? ' selected' : '',
3040: htmlquote($_));
3.120 scop 3041: }
3.144 scop 3042: print <<EOF
3043: </select>
3044: </td>
3045: <td></td>
3046: </tr>
3047: EOF
3.120 scop 3048: }
3049:
3.144 scop 3050: print <<EOF;
3051: <tr>
3052: <td align="right">
3053: <a name="logsort"></a>
3054: <label for="logsort" accesskey="L">Sort log by:</label>
3055: </td><td>
3056: EOF
3.120 scop 3057: printLogSortSelect($use_java_script);
3.144 scop 3058: print <<EOF;
3059: </td>
3060: <td><input type="submit" value=" Set " accesskey="S"></td>
3061: </tr>
3062: </table>
3063: EOF
3.154 scop 3064: foreach (@stickyvars) {
3065: next if ($_ eq "f");
3066: next if ($_ eq "only_with_tag");
3067: next if ($_ eq "logsort");
3068: printf("<input type=\"hidden\" name=\"$_\" value=\"%s\">\n",
3069: htmlquote($input{$_}))
3070: if (defined($input{$_})
3071: && (!defined($DEFAULTVALUE{$_})
3072: || $input{$_} ne $DEFAULTVALUE{$_})
3073: && $input{$_} ne "");
3074: }
3075: print "</form>\n";
3.120 scop 3076: html_footer();
3077: }
3078:
3079: sub flush_diff_rows($$$$)
3080: {
3081: my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
3082:
3083: if (!defined($state)) {
3084: return;
3085: }
3086:
3087: if ($state eq "PreChangeRemove") { # we just got remove-lines before
3.133 scop 3088: for (my $j = 0; $j < $leftRow; $j++) {
3.144 scop 3089: printf(<<EOF, scalar(@$leftColRef[$j]));
3090: <tr>
3091: <td class="diff-removed"> %s</td>
3092: <td class="diff-empty"> </td>
3093: </tr>
3094: EOF
3.120 scop 3095: }
3096: } elsif ($state eq "PreChange") { # state eq "PreChange"
3097: # we got removes with subsequent adds
3098:
3.133 scop 3099: for (my $j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump both cols
3.120 scop 3100: print "<tr>\n";
3101: if ($j < $leftRow) {
3102: print "<td class=\"diff-changed\"> @$leftColRef[$j]</td>";
3103: } else {
3104: print "<td class=\"diff-changed-missing\"> </td>";
3105: }
3106: print "\n";
3107:
3108: if ($j < $rightRow) {
3109: print "<td class=\"diff-changed\"> @$rightColRef[$j]</td>";
3110: } else {
3111: print "<td class=\"diff-changed-missing\"> </td>";
3112: }
3113: print "\n</tr>\n";
3114: }
3115: }
3.1 knu 3116: }
3117:
3118: ##
3119: # Function to generate Human readable diff-files
3120: # human_readable_diff(String revision_to_return_to);
3121: ##
3.144 scop 3122: sub human_readable_diff($$)
3.120 scop 3123: {
3124: my ($fh, $rev) = @_;
3.144 scop 3125:
3.120 scop 3126: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
3127:
3.144 scop 3128: (my $where_nd = $where) =~ s/.diff$//;
3129: (my $filename = $where_nd) =~ s/^.*\///;
3130: (my $pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
3131: (my $scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
3.120 scop 3132:
3.133 scop 3133: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, 'diff');
3.120 scop 3134:
3135: # Read header to pick up read revision and date, if possible
3136: while (<$fh>) {
3137: ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
3138: ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
3139: last if (/^\+\+\+ /);
3140: }
3141:
3142: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
3143: $rev1 = $r1r;
3144: $date1 = $r1d;
3145: }
3146: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
3147: $rev2 = $r2r;
3148: $date2 = $r2d;
3149: }
3150:
3.144 scop 3151: # Using <table style=\"border: none\" here breaks NS 4.x badly...
3152: printf(<<EOF, $where_nd, $rev1, $rev2, $rev1);
3153: <h3 style="text-align: center">Diff for /%s between versions %s and %s</h3>
3.147 scop 3154: <table border="0" cellspacing="0" cellpadding="0" width="100%%">
3.144 scop 3155: <tr style="background-color: #ffffff">
3.147 scop 3156: <th style="text-align: center; vertical-align: top" width="50%%">version %s
3.144 scop 3157: EOF
3158: print ', ', $date1 if defined($date1);
3159: print "<br>Tag: $sym1\n" if $sym1;
3160: printf(<<EOF, $rev2);
3161: </th>
3.147 scop 3162: <th style="text-align: center; vertical-align: top" width="50%%">version %s
3.144 scop 3163: EOF
3164: print ', ', $date2 if defined($date2);
3165: print "<br>Tag: $sym2\n" if $sym2;
3.120 scop 3166: print "</th>\n";
3167:
3168: # Process diff text
3169: # prefetch several lines
3170: my @buf = head($fh);
3.144 scop 3171: my %d = scan_directives(@buf);
3.120 scop 3172:
3.144 scop 3173: my $leftRow = 0;
3174: my $rightRow = 0;
3175: my ($difftxt, @rightCol, @leftCol, $oldline, $newline, $funname);
3176: my ($diffcode, $rest);
3.120 scop 3177:
3178: while (@buf || !eof($fh)) {
3179: $difftxt = @buf ? shift @buf : <$fh>;
3180:
3181: if ($difftxt =~ /^@@/) {
3182: ($oldline, $newline, $funname) =
3183: $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
3184: $funname = htmlquote($funname);
3185: $funname =~ s/\s/ /go;
3.144 scop 3186:
3187: printf(<<EOF, $oldline, $funname, $newline, $funname);
3188: <tr class="diff-heading">
3.147 scop 3189: <td width="50%%">
3190: <table width="100%%" border="1" cellpadding="5">
3.144 scop 3191: <tr>
3192: <td><b>Line %s</b> <span style="font-size: smaller">%s</span></td>
3193: </tr>
3194: </table>
3.147 scop 3195: </td><td width="50%%">
3196: <table width="100%%" border="1" cellpadding="5">
3.144 scop 3197: <tr>
3198: <td><b>Line %s</b> <span style="font-size: smaller">%s</span></td>
3199: </tr>
3200: </table>
3201: </td>
3202: EOF
3203:
3.120 scop 3204: $state = "dump";
3205: $leftRow = 0;
3206: $rightRow = 0;
3207: } else {
3208: ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
3209: $_ = spacedHtmlText($rest, $d{'tabstop'});
3210:
3211: #########
3212: # little state machine to parse unified-diff output (Hen, zeller@think.de)
3213: # in order to get some nice 'ediff'-mode output
3214: # states:
3215: # "dump" - just dump the value
3216: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
3217: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
3218: ##########
3219:
3220: if ($diffcode eq '+') {
3221: if ($state eq "dump")
3222: { # 'change' never begins with '+': just dump out value
3.144 scop 3223: printf(<<EOF, $_);
3224: <tr>
3225: <td class="diff-empty"> </td>
3226: <td class="diff-added"> %s</td>
3227: </tr>
3228: EOF
3.120 scop 3229: } else { # we got minus before
3230: $state = "PreChange";
3231: $rightCol[$rightRow++] = $_;
3232: }
3233: } elsif ($diffcode eq '-') {
3234: $state = "PreChangeRemove";
3235: $leftCol[$leftRow++] = $_;
3236: } else { # empty diffcode
3237: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3.147 scop 3238: printf(<<EOF, $_, $_);
3.144 scop 3239: <tr>
3240: <td class="diff-same"> %s</td>
3241: <td class="diff-same"> %s</td>
3242: </tr>
3243: EOF
3.120 scop 3244: $state = "dump";
3245: $leftRow = 0;
3246: $rightRow = 0;
3247: }
3248: }
3249: }
3250: close($fh);
3251:
3252: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3253:
3254: # state is empty if we didn't have any change
3255: if (!$state) {
3.144 scop 3256: print <<EOF;
3257: <tr>
3258: <td colspan="2"> </td>
3259: </tr>
3260: <tr class="diff-empty">
3261: <td colspan="2" align="center"><b>- No viewable change -</b></td>
3262: </tr>
3263: EOF
3.120 scop 3264: }
3265:
3.144 scop 3266: printf(<<EOF, $scriptwhere, $rev1, $rev2);
3267: </table>
3.147 scop 3268: <hr style="width: 100%%" noshade>
3.144 scop 3269: <form method="get" action="%s">
3270: <table style="border: none">
3271: <tr>
3272: <td>
3273: <table border="1">
3274: <tr>
3275: <td>
3276: Legend:<br>
3277: <table style="border: none" cellspacing="0" cellpadding="1">
3278: <tr>
3279: <td align="center" class="diff-removed">Removed from v.%s</td>
3280: <td class="diff-empty"> </td>
3281: </tr><tr class="diff-changed">
3282: <td align="center" colspan="2">changed lines</td>
3283: </tr><tr>
3284: <td class="diff-empty"> </td>
3285: <td align="center" class="diff-added">Added in v.%s</td>
3286: </tr>
3287: </table>
3288: </td>
3289: </tr>
3290: </table>
3291: </td>
3292: <td>
3293: EOF
3.120 scop 3294:
3295: # Print format selector
3296: foreach my $var (keys %input) {
3297: next if ($var eq "f");
3298: next if (defined($DEFAULTVALUE{$var})
3299: && $DEFAULTVALUE{$var} eq $input{$var});
3300: print "<input type=\"hidden\" name=\"", urlencode($var), "\" value=\"",
3301: urlencode($input{$var}), "\">\n";
3302: }
3303: printDiffSelect($use_java_script);
3304:
3.144 scop 3305: print <<EOF;
3306: <input type="submit" value="Show">
3307: </td>
3308: </tr>
3309: </table>
3310: </form>
3311: EOF
3.120 scop 3312: }
3313:
3.163 ! scop 3314: sub navigateHeader($$$$$;$)
3.120 scop 3315: {
3.163 ! scop 3316: my ($swhere, $path, $filename, $rev, $title, $moddate) = @_;
3.120 scop 3317: $swhere = "" if ($swhere eq $scriptwhere);
3318: $swhere = './' . urlencode($filename) if ($swhere eq "");
3319:
3.136 scop 3320: my $qfile = htmlquote($filename);
3321: my $qpath = htmlquote($path);
3.100 knu 3322:
3.163 ! scop 3323: http_header('', $moddate);
3.133 scop 3324:
3.120 scop 3325: print <<EOF;
3.100 knu 3326: $HTML_DOCTYPE
3.89 knu 3327: <html>
3328: <head>
3.136 scop 3329: <title>$qpath$qfile - $title - $rev</title>
3.144 scop 3330: $HTML_META$CSS</head>
3.129 scop 3331: <body class="src">
3332: <table width="100%" class="navigate-header" style="border: none" cellspacing="0" cellpadding="1">
3.144 scop 3333: <tr valign="bottom">
3334: <td>
3.64 knu 3335: EOF
3336:
3.120 scop 3337: print &link($backicon, "$swhere$query#rev$rev");
3.136 scop 3338: printf '<b>Return to %s CVS log',
3339: &link(htmlquote($filename), "$swhere$query#rev$rev");
3.120 scop 3340: print "</b> $fileicon</td>";
3341:
3.144 scop 3342: printf(<<EOF, $diricon, &clickablePath($path, 1));
3343: <td align="right">%s <b>Up to %s</b></td>
3344: </tr>
3345: </table>
3346: EOF
3.120 scop 3347: }
3348:
3349: sub plural_write($$)
3350: {
3351: my ($num, $text) = @_;
3352: if ($num != 1) {
3353: $text .= "s";
3354: }
3355:
3356: if ($num > 0) {
3357: return join (' ', $num, $text);
3358: } else {
3359: return "";
3360: }
3.1 knu 3361: }
3362:
3363: ##
3364: # print readable timestamp in terms of
3365: # '..time ago'
3366: # H. Zeller <zeller@think.de>
3367: ##
3.120 scop 3368: sub readableTime($$)
3369: {
3370: my ($secs, $long) = @_;
3371:
3372: # this function works correct for time >= 2 seconds
3373: if ($secs < 2) {
3374: return "very little time";
3375: }
3376:
3377: my %desc = (
3.133 scop 3378: 1 => 'second',
3379: 60 => 'minute',
3380: 3600 => 'hour',
3381: 86400 => 'day',
3382: 604800 => 'week',
3383: 2628000 => 'month',
3384: 31536000 => 'year'
3385: );
3386:
3.120 scop 3387: my @breaks = sort { $a <=> $b } keys %desc;
3.133 scop 3388: my $i = 0;
3.120 scop 3389:
3390: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3391: $i++;
3392: }
3393: $i--;
3.133 scop 3394: my $break = $breaks[$i];
3395: my $retval = plural_write(int($secs / $break), $desc{$break});
3.120 scop 3396:
3397: if ($long == 1 && $i > 0) {
3398: my $rest = $secs % $break;
3399: $i--;
3400: $break = $breaks[$i];
3401: my $resttime = plural_write(int($rest / $break), $desc{$break});
3402: if ($resttime) {
3403: $retval .= ", $resttime";
3404: }
3405: }
3.1 knu 3406:
3.120 scop 3407: return $retval;
3.1 knu 3408: }
3409:
3410: ##
3411: # clickablePath(String pathname, boolean last_item_clickable)
3412: #
3413: # returns a html-ified path whereas each directory is a link for
3414: # faster navigation. last_item_clickable controls whether the
3415: # basename (last directory/file) is a link as well
3416: ##
3.120 scop 3417: sub clickablePath($$)
3418: {
3419: my ($pathname, $clickLast) = @_;
3420:
3.154 scop 3421: my $root = '[' . htmlquote($CVSROOTdescr{$cvstree} || $cvstree) . ']';
3422:
3.144 scop 3423: # This should never happen (see chooseCVSRoot()), but let's be sure...
3.154 scop 3424: return $root if ($pathname eq '/');
3.120 scop 3425:
3.144 scop 3426: my $retval =
3.154 scop 3427: ' ' . &link($root, sprintf('%s/%s#dirlist', $scriptname, $query));
3.144 scop 3428: my $wherepath = '';
3429: my ($lastslash) = $pathname =~ m|/$|;
3430:
3431: foreach (split (/\//, $pathname)) {
3432: $retval .= ' / ';
3433: $wherepath .= "/$_";
3434: my $last = "$wherepath/" eq "/$pathname" || $wherepath eq "/$pathname";
3435:
3436: if ($clickLast || !$last) {
3437: $retval .= &link(htmlquote($_),
3438: join ('',
3439: $scriptname, urlencode($wherepath),
3440: (!$last || $lastslash ? '/' : ''), $query,
3441: (!$last || $lastslash ? "#dirlist" : "")));
3442: } else { # do not make a link to the current dir
3443: $retval .= htmlquote($_);
3.120 scop 3444: }
3445: }
3446: return $retval;
3447: }
3448:
3.144 scop 3449:
3.120 scop 3450: sub chooseCVSRoot()
3451: {
3452:
3453: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3454: if (2 <= @CVSROOT) {
3.133 scop 3455: foreach my $k (keys %input) {
3.154 scop 3456: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\">\n",
3457: htmlquote($k), htmlquote($input{$k}))
3458: if ($input{$k} && $k ne 'cvsroot');
3.120 scop 3459: }
3460:
3461: # Form-Elements look wierd in Netscape if the background
3462: # isn't gray and the form elements are not placed
3463: # within a table ...
3.144 scop 3464: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3465: <table style="border: none">
3466: <tr>
3467: <td><label for="cvsroot" accesskey="C">CVS Root:</label></td>
3468: <td>
3469: <select id="cvsroot" name="cvsroot"%s>
3470: EOF
3.120 scop 3471:
3.133 scop 3472: foreach my $k (@CVSROOT) {
3.136 scop 3473: printf("<option value=\"%s\"%s>%s</option>\n",
3474: htmlquote($k),
3475: ($k eq $cvstree) ? ' selected' : '',
3476: htmlquote($CVSROOTdescr{$k} || $k));
3.120 scop 3477: }
3478: print "</select>\n</td>\n<td>";
3479: } else {
3480:
3481: # no choice -- but we need the form to select module/path,
3482: # at least for Netscape
3.154 scop 3483: printf "<p>\nCVS Root: <b>[%s]</b>",
3484: htmlquote($CVSROOTdescr{$cvstree} || $cvstree);
3.120 scop 3485: }
3486:
3.144 scop 3487: print <<EOF;
3488: <label for="mpath" accesskey="M">
3489: Module path or alias:
3490: <input type="text" id="mpath" name="path" value="" size="15">
3491: </label>
3492: <input type="submit" value="Go" accesskey="O">
3493: EOF
3.120 scop 3494:
3.144 scop 3495: print 2 <= @CVSROOT ? "</td>\n</tr>\n</table>" : '</p>';
3.120 scop 3496: print "\n</form>";
3497: }
3498:
3499: sub chooseMirror()
3500: {
3501:
3502: # This code comes from the original BSD-cvsweb
3503: # and may not be useful for your site; If you don't
3504: # set %MIRRORS this won't show up, anyway.
3505: scalar(%MIRRORS) or return;
3506:
3507: # Should perhaps exclude the current site somehow...
3508: print "\n<p>\nThis CVSweb is mirrored in\n";
3509:
3510: my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}), sort keys %MIRRORS);
3511: my $tmp = pop (@tmp);
3512:
3513: if (scalar(@tmp)) {
3514: print join (', ', @tmp), ' and ';
3515: }
3516:
3517: print "$tmp.\n</p>\n";
3518: }
3519:
3520: sub fileSortCmp()
3521: {
3522: my ($comp) = 0;
3523: my ($c, $d, $af, $bf);
3524:
3525: ($af = $a) =~ s/,v$//;
3526: ($bf = $b) =~ s/,v$//;
3527: my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
3528: if (defined($fileinfo{$af}));
3529: my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
3530: if (defined($fileinfo{$bf}));
3531:
3.140 scop 3532: if (defined($filename1) && defined($filename2) &&
3533: $af eq $filename1 && $bf eq $filename2)
3.120 scop 3534: {
3535:
3536: # Two files
3.140 scop 3537: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
3538: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
3539: if ($input{ignorecase}) {
3540: $comp = (uc($log1) cmp uc($log2)) if ($bylog && $log1 && $log2);
3541: $comp = (uc($author1) cmp uc($author2)) if ($byauthor &&
3542: $author1 && $author2);
3543: } else {
3544: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
3545: $comp = ($author1 cmp $author2) if ($byauthor &&
3546: $author1 && $author2);
3547: }
3.120 scop 3548: }
3549:
3550: if ($comp == 0) {
3551:
3552: # Directories first, then files under version control,
3553: # then other, "rogue" files.
3554: # Sort by filename if no other criteria available.
3555:
3556: my $ad = (
3557: (-d "$fullname/$a")
3558: ? 'D'
3559: : (defined($fileinfo{$af}) ? 'F' : 'R')
3560: );
3561: my $bd = (
3562: (-d "$fullname/$b")
3563: ? 'D'
3564: : (defined($fileinfo{$bf}) ? 'F' : 'R')
3565: );
3566: ($c = $a) =~ s|.*/||;
3567: ($d = $b) =~ s|.*/||;
3.144 scop 3568:
3569: my ($l, $r) = ("$ad$c", "$bd$d");
3570: $comp = $input{ignorecase} ? (uc($l) cmp uc($r)) : ($l cmp $r);
3571:
3572: # Parent dir is always first, then Attic.
3573: if ($comp != 0) {
3574: if ($l eq 'D..') {
3.149 scop 3575: $comp = -1;
3.144 scop 3576: } elsif ($r eq 'D..') {
3.149 scop 3577: $comp = 1;
3.144 scop 3578: } elsif ($l eq 'DAttic') {
3.149 scop 3579: $comp = -1;
3.144 scop 3580: } elsif ($r eq 'DAttic') {
3.149 scop 3581: $comp = 1;
3.144 scop 3582: }
3583: }
3.120 scop 3584: }
3585: return $comp;
3.1 knu 3586: }
3587:
3588: # make A url for downloading
3.120 scop 3589: sub download_url($$;$)
3590: {
3591: my ($url, $revision, $mimetype) = @_;
3.1 knu 3592:
3.120 scop 3593: $revision =~ s/\b0\.//;
3.1 knu 3594:
3.146 scop 3595: if (defined($checkoutMagic) &&
3596: (!defined($mimetype) || $mimetype !~ $CvsWebMarkupRE))
3.120 scop 3597: {
3598: my $path = $where;
3599: $path =~ s|[^/]+$||;
3600: $url = "$scriptname/$checkoutMagic/${path}$url";
3601: }
3602: $url .= "?rev=$revision";
3603: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67 knu 3604:
3.120 scop 3605: $url;
3.1 knu 3606: }
3607:
3.12 knu 3608: # Presents a link to download the
3.1 knu 3609: # selected revision
3.120 scop 3610: sub download_link($$$;$)
3611: {
3612: my ($url, $revision, $textlink, $mimetype) = @_;
3613: my ($fullurl) = download_url($url, $revision, $mimetype);
3614:
3615: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3616:
3.159 scop 3617: printf '<a href="%s" class="download-link"', hrefquote("$fullurl$barequery");
3.120 scop 3618:
3.146 scop 3619: if ($open_extern_window &&
3620: (!defined($mimetype) || $mimetype !~ $CvsWebMarkupRE))
3.120 scop 3621: {
3622: print ' target="cvs_checkout"';
3623:
3624: # we should have
3625: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3626: # in order to allow the user to resize the window; otherwise
3627: # the user may resize the window, but on next checkout - zap -
3628: # its original (configured s. cvsweb.conf) size is back again
3629: # .. annoying (if $extern_window_(width|height) is defined)
3630: # but this if (..) solution is far from perfect
3631: # what we need to do as well is
3632: # 1) save cvswin in an invisible frame that always exists
3633: # (document.cvswin will be void on next load)
3634: # 2) on close of the cvs_checkout - window set the cvswin
3635: # variable to 'null' again - so that it will be
3636: # reopenend with the configured size
3637: # anyone a JavaScript programmer ?
3638: # .. so here without if (..):
3639: # currently, the best way is to comment out the size parameters
3640: # ($extern_window...) in cvsweb.conf.
3641: if ($use_java_script) {
3.159 scop 3642: my @attr = qw(resizable scrollbars menubar);
3.120 scop 3643:
3644: push @attr, qw(status toolbar)
3645: if (defined($mimetype) && $mimetype eq "text/html");
3646:
3647: push @attr, "width=$extern_window_width"
3648: if (defined($extern_window_width));
3649:
3650: push @attr, "height=$extern_window_height"
3651: if (defined($extern_window_height));
3652:
3653: # We need the "return false" here to prevent browsers
3654: # from following the href after the onclick handler.
3655: # This would effectively load the same document in
3656: # the same window *twice*.
3657: printf q` onclick="window.open('%s','cvs_checkout','%s');return false"`,
3658: hrefquote("$fullurl$barequery"), join (',', @attr);
3659: }
3660: }
3.159 scop 3661: print ">$textlink</a>";
3.132 scop 3662: }
3663:
3664: sub graph_link($$;$)
3665: {
3666: my ($url, $revision, $text) = @_;
3667: $text ||= $graphicon;
3668: return sprintf('<a href="%s?graph=%s%s">%s</a>',
3669: hrefquote($url), hrefquote($revision), hrefquote($barequery),
3670: $text);
3.1 knu 3671: }
3672:
3673: # Returns a Query string with the
3674: # specified parameter toggled
3.140 scop 3675: sub toggleQuery($;$)
3.120 scop 3676: {
3677: my ($toggle, $value) = @_;
3.133 scop 3678:
3679: my %vars = %input;
3.120 scop 3680:
3681: if (defined($value)) {
3682: $vars{$toggle} = $value;
3683: } else {
3684: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3685: }
3686:
3687: # Build a new query of non-default paramenters
3.133 scop 3688: my $newquery = "";
3689: foreach my $var (@stickyvars) {
3.120 scop 3690: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3691: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3692:
3693: if ($value ne $default) {
3694: $newquery .= "&" if ($newquery ne "");
3695: $newquery .= urlencode($var) . "=" . urlencode($value);
3696: }
3697: }
3698:
3699: if ($newquery) {
3700: return '?' . $newquery;
3701: }
3702: return "";
3703: }
3704:
3705: sub urlencode($)
3706: {
3707: local ($_) = @_;
3708:
3709: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3710:
3711: $_;
3712: }
3713:
3714: sub htmlquote($)
3715: {
3716: local ($_) = @_;
3717:
3718: # Special Characters; RFC 1866
3719: s/&/&/g;
3720: s/\"/"/g;
3721: s/</</g;
3722: s/>/>/g;
3723:
3724: $_;
3725: }
3726:
3727: sub htmlunquote($)
3728: {
3729: local ($_) = @_;
3730:
3731: # Special Characters; RFC 1866
3732: s/"/\"/g;
3733: s/</</g;
3734: s/>/>/g;
3735: s/&/&/g;
3736:
3737: $_;
3738: }
3739:
3740: sub hrefquote($)
3741: {
3742: local ($_) = @_;
3743:
3744: y/ /+/;
3745:
3746: htmlquote($_);
3747: }
3748:
3.163 ! scop 3749: sub http_header(;$$)
3.120 scop 3750: {
3.163 ! scop 3751: my ($content_type, $moddate) = @_;
! 3752: $content_type ||= 'text/html';
3.120 scop 3753:
3754: $content_type .= "; charset=$charset"
3.163 ! scop 3755: if ($charset && $content_type =~ m,^text/,);
3.120 scop 3756:
3.163 ! scop 3757: if ($moddate) {
3.120 scop 3758: if ($is_mod_perl) {
3759: Apache->request->header_out(
3760: "Last-Modified" => scalar gmtime($moddate) . " GMT");
3761: } else {
3762: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
3763: }
3764: }
3765:
3766: if ($is_mod_perl) {
3767: Apache->request->content_type($content_type);
3768: } else {
3769: print "Content-Type: $content_type\r\n";
3770: }
3771:
3772: if ($allow_compress && $maycompress) {
3773: if ($has_zlib
3774: || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c")))
3775: {
3776:
3777: if ($is_mod_perl) {
3778: Apache->request->content_encoding("x-gzip");
3779: Apache->request->header_out(Vary => "Accept-Encoding");
3780: Apache->request->send_http_header;
3781: } else {
3782: print "Content-Encoding: x-gzip\r\n";
3783: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3784: print "\r\n"; # Close headers
3785: }
3786: $| = 1;
3787: $| = 0; # Flush header output
3788:
3789: if ($has_zlib) {
3790: tie *GZIP, __PACKAGE__, \*STDOUT;
3791: }
3792: select(GZIP);
3793: $gzip_open = 1;
3794:
3.149 scop 3795: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
3.120 scop 3796: } else {
3797: if ($is_mod_perl) {
3798: Apache->request->send_http_header;
3799: } else {
3800: print "\r\n"; # Close headers
3801: }
3802: print
3803: "<span style=\"font-size: smaller\">Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</span><br>";
3804: }
3805: } else {
3806:
3807: if ($is_mod_perl) {
3808: Apache->request->send_http_header;
3809: } else {
3810: print "\r\n"; # Close headers
3811: }
3812: }
3813: }
3814:
3.131 scop 3815:
3.163 ! scop 3816: sub html_header($;$)
3.120 scop 3817: {
3.163 ! scop 3818: my ($title, $moddate) = @_;
! 3819: $title = htmlquote($title);
3.162 scop 3820: my $l = $logo || '';
3.163 ! scop 3821: http_header('text/html', $moddate);
3.120 scop 3822: print <<EOH;
3.100 knu 3823: $HTML_DOCTYPE
3.1 knu 3824: <html>
3.40 knu 3825: <head>
3.134 scop 3826: <title>$title</title>
3.144 scop 3827: $HTML_META$CSS</head>
3.129 scop 3828: <body>
3.162 scop 3829: $l <h1 align="center">$title</h1>
3.1 knu 3830: EOH
3831: }
3832:
3.120 scop 3833: sub html_footer()
3834: {
3.127 scop 3835: print "<hr noshade>\n<address>$address</address>\n" if $address;
3836: print "</body>\n</html>\n";
3.1 knu 3837: }
3838:
3.120 scop 3839: sub link_tags($)
3840: {
3841: my ($tags) = @_;
3842: my ($ret) = "";
3843: my ($fileurl, $filename);
3844:
3845: ($filename = $where) =~ s/^.*\///;
3846: $fileurl = './' . urlencode($filename);
3847:
3848: foreach my $sym (split (", ", $tags)) {
3849: $ret .= ",\n" if ($ret ne "");
3.136 scop 3850: $ret .= &link(htmlquote($sym),
3851: $fileurl . toggleQuery('only_with_tag', $sym));
3.120 scop 3852: }
3853: return "$ret\n";
3.1 knu 3854: }
3855:
3856: #
3.81 knu 3857: # See if a module is listed in the config file's @HideModules list.
3.1 knu 3858: #
3.120 scop 3859: sub forbidden_module($)
3860: {
3861: my ($module) = @_;
3862: local $_;
3863:
3864: for (@HideModules) {
3865: return 1 if $module =~ $_;
3866: }
3867: return 0;
3868: }
3869:
3870: sub forbidden_file($)
3871: {
3872: my ($path) = @_;
3873: $path = substr($path, length($cvsroot) + 1);
3874: local $_;
3875: for (@ForbiddenFiles) {
3876: return 1 if $path =~ $_;
3877: }
3878: return 0;
3.129 scop 3879: }
3880:
3.25 knu 3881:
3882: # Close the GZIP handle remove the tie.
3883:
3.120 scop 3884: sub gzipclose
3885: {
3886: if ($gzip_open) {
3887: select(STDOUT);
3888: close(GZIP);
3889: untie *GZIP;
3890: $gzip_open = 0;
3891: }
3.23 knu 3892: }
3893:
3894: # implement a gzipped file handle via the Compress:Zlib compression
3895: # library.
3896:
3897: sub MAGIC1() { 0x1f }
3898: sub MAGIC2() { 0x8b }
3.80 knu 3899: sub OSCODE() { 3 }
3.23 knu 3900:
3.120 scop 3901: sub TIEHANDLE
3902: {
3903: my ($class, $out) = @_;
3904: my ($d) = Compress::Zlib::deflateInit(
3905: -Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3906: -WindowBits => -Compress::Zlib::MAX_WBITS()
3907: )
3908: or return undef;
3909: my ($o) = { handle => $out,
3910: dh => $d,
3911: crc => 0,
3912: len => 0,
3913: };
3914: my ($header) = pack("c10",
3915: MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(),
3916: 0, 0, 0, 0, 0, 0, OSCODE);
3917: print {$o->{handle}} $header;
3918: return bless($o, $class);
3919: }
3920:
3921: sub PRINT
3922: {
3923: my ($o) = shift;
3924: my ($buf) = join (defined $, ? $, : "", @_);
3925: my ($len) = length($buf);
3926: my ($compressed, $status) = $o->{dh}->deflate($buf);
3927: print {$o->{handle}} $compressed if defined($compressed);
3928: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3929: $o->{len} += $len;
3930: return $len;
3931: }
3932:
3933: sub PRINTF
3934: {
3935: my ($o) = shift;
3936: my ($fmt) = shift;
3937: my ($buf) = sprintf($fmt, @_);
3938: my ($len) = length($buf);
3939: my ($compressed, $status) = $o->{dh}->deflate($buf);
3940: print {$o->{handle}} $compressed if defined($compressed);
3941: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3942: $o->{len} += $len;
3943: return $len;
3944: }
3945:
3946: sub WRITE
3947: {
3948: my ($o, $buf, $len, $off) = @_;
3949: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3950: print {$o->{handle}} $compressed if defined($compressed);
3951: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3952: $o->{len} += $len;
3953: return $len;
3954: }
3955:
3956: sub CLOSE
3957: {
3958: my ($o) = @_;
3959: return if !defined($o->{dh});
3960: my ($buf) = $o->{dh}->flush();
3961: $buf .= pack("V V", $o->{crc}, $o->{len});
3962: print {$o->{handle}} $buf;
3963: undef $o->{dh};
3964: }
3965:
3966: sub DESTROY
3967: {
3968: my ($o) = @_;
3969: CLOSE($o);
1.1 jfieber 3970: }
3.149 scop 3971:
3972: # Local variables:
3973: # indent-tabs-mode: nil
3974: # cperl-indent-level: 2
3975: # End:
CVSweb