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