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