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