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