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