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