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