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