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