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