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