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