stas 2003/06/06 02:23:47 Modified: src/docs/2.0/user config.cfg Added: src/docs/2.0/user/porting/code apache_mp3_2.diff apache_mp3_7.diff apache_mp3_9.diff Log: several long patches live in their own files Revision Changes Path 1.25 +3 -0 modperl-docs/src/docs/2.0/user/config.cfg Index: config.cfg =================================================================== RCS file: /home/cvs/modperl-docs/src/docs/2.0/user/config.cfg,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- config.cfg 23 May 2003 08:55:50 -0000 1.24 +++ config.cfg 6 Jun 2003 09:23:47 -0000 1.25 @@ -62,5 +62,8 @@ changes => 'Changes.pod', + copy_glob => [qw( + porting/code + )], ); 1.1 modperl-docs/src/docs/2.0/user/porting/code/apache_mp3_2.diff Index: apache_mp3_2.diff =================================================================== --- Apache/MP3.pm.2 2003-06-06 15:17:22.000000000 +1000 +++ Apache/MP3.pm 2003-06-06 15:16:21.000000000 +1000 @@ -55,6 +55,14 @@ my $NO = '^(no|false)$'; # regular expression my $YES = '^(yes|true)$'; # regular expression +sub get_config { + my $val = shift->r->dir_config(shift); + return defined $val ? $val : ''; +} + +sub config_yes { shift->get_config(shift) !~ /$YES/oi; } +sub config_no { shift->get_config(shift) !~ /$NO/oi; } + sub handler : method { my $class = shift; my $obj = $class->new(@_) or die "Can't create object: $!"; @@ -70,7 +78,7 @@ my @lang_tags; push @lang_tags,split /,\s+/,$r->header_in('Accept-language') if $r->header_in('Accept-language'); - push @lang_tags,$r->dir_config('DefaultLanguage') || 'en-US'; + push @lang_tags,$new->get_config('DefaultLanguage') || 'en-US'; $new->{'lh'} ||= Apache::MP3::L10N->get_handle(@lang_tags) @@ -343,7 +351,7 @@ my $file = $subr->filename; my $type = $subr->content_type; my $data = $self->fetch_info($file,$type); - my $format = $self->r->dir_config('DescriptionFormat'); + my $format = $self->get_config('DescriptionFormat'); if ($format) { $r->print('#EXTINF:' , $data->{seconds} , ','); (my $description = $format) =~ s{%([atfglncrdmsqS%])} @@ -1204,7 +1212,7 @@ # get fields to display in list of MP3 files sub fields { my $self = shift; - my @f = split /\W+/,$self->r->dir_config('Fields'); + my @f = split /\W+/,$self->get_config('Fields'); return map { lc $_ } @f if @f; # lower case return qw(title artist duration bitrate); # default } @@ -1340,7 +1348,7 @@ sub get_dir { my $self = shift; my ($config,$default) = @_; - my $dir = $self->r->dir_config($config) || $default; + my $dir = $self->get_config($config) || $default; return $dir if $dir =~ m!^/!; # looks like a path return $dir if $dir =~ m!^\w+://!; # looks like a URL return $self->default_dir . '/' . $dir; @@ -1348,22 +1356,22 @@ # return true if downloads are allowed from this directory sub download_ok { - shift->r->dir_config('AllowDownload') !~ /$NO/oi; + shift->config_no('AllowDownload'); } # return true if streaming is allowed from this directory sub stream_ok { - shift->r->dir_config('AllowStream') !~ /$NO/oi; + shift->config_no('AllowStream'); } # return true if playing locally is allowed sub playlocal_ok { - shift->r->dir_config('AllowPlayLocally') =~ /$YES/oi; + shift->config_yes('AllowPlayLocally'); } # return true if we should check that the client can accomodate streaming sub check_stream_client { - shift->r->dir_config('CheckStreamClient') =~ /$YES/oi; + shift->config_yes('CheckStreamClient'); } # return true if client can stream @@ -1378,48 +1386,48 @@ # whether to read info for each MP3 file (might take a long time) sub read_mp3_info { - shift->r->dir_config('ReadMP3Info') !~ /$NO/oi; + shift->config_no('ReadMP3Info'); } # whether to time out streams sub stream_timeout { - shift->r->dir_config('StreamTimeout') || 0; + shift->get_config('StreamTimeout') || 0; } # how long an album list is considered so long we should put buttons # at the top as well as the bottom -sub file_list_is_long { shift->r->dir_config('LongList') || 10 } +sub file_list_is_long { shift->get_config('LongList') || 10 } sub home_label { my $self = shift; - my $home = $self->r->dir_config('HomeLabel') || + my $home = $self->get_config('HomeLabel') || $self->x('Home'); return lc($home) eq 'hostname' ? $self->r->hostname : $home; } sub path_style { # style for the path to parent directories - lc(shift->r->dir_config('PathStyle')) || 'staircase'; + lc(shift->get_config('PathStyle')) || 'staircase'; } # where is our cache directory (if any) sub cache_dir { my $self = shift; - return unless my $dir = $self->r->dir_config('CacheDir'); + return unless my $dir = $self->get_config('CacheDir'); return $self->r->server_root_relative($dir); } # columns to display -sub subdir_columns {shift->r->dir_config('SubdirColumns') || SUBDIRCOLUMNS } -sub playlist_columns {shift->r->dir_config('PlaylistColumns') || PLAYLISTCOLUMNS } +sub subdir_columns {shift->get_config('SubdirColumns') || SUBDIRCOLUMNS } +sub playlist_columns {shift->get_config('PlaylistColumns') || PLAYLISTCOLUMNS } # various configuration variables -sub default_dir { shift->r->dir_config('BaseDir') || BASE_DIR } +sub default_dir { shift->get_config('BaseDir') || BASE_DIR } sub stylesheet { shift->get_dir('Stylesheet', STYLESHEET) } sub parent_icon { shift->get_dir('ParentIcon',PARENTICON) } sub cd_list_icon { my $self = shift; my $subdir = shift; - my $image = $self->r->dir_config('CoverImageSmall') || COVERIMAGESMALL; + my $image = $self->get_config('CoverImageSmall') || COVERIMAGESMALL; my $directory_specific_icon = $self->r->filename."/$subdir/$image"; return -e $directory_specific_icon ? join ("/",$self->r->uri,escape($subdir),$image) @@ -1427,7 +1435,7 @@ } sub playlist_icon { my $self = shift; - my $image = $self->r->dir_config('PlaylistImage') || PLAYLISTIMAGE; + my $image = $self->get_config('PlaylistImage') || PLAYLISTIMAGE; my $directory_specific_icon = $self->r->filename."/$image"; warn $directory_specific_icon; return -e $directory_specific_icon @@ -1444,7 +1452,7 @@ sub cd_icon { my $self = shift; my $dir = shift; - my $coverimg = $self->r->dir_config('CoverImage') || COVERIMAGE; + my $coverimg = $self->get_config('CoverImage') || COVERIMAGE; if (-e "$dir/$coverimg") { $coverimg; } else { @@ -1453,7 +1461,7 @@ } sub missing_comment { my $self = shift; - my $missing = $self->r->dir_config('MissingComment'); + my $missing = $self->get_config('MissingComment'); return if $missing eq 'off'; $missing = $self->lh->maketext('unknown') unless $missing; $missing; @@ -1464,7 +1472,7 @@ my $self = shift; my $data = shift; my $description; - my $format = $self->r->dir_config('DescriptionFormat'); + my $format = $self->get_config('DescriptionFormat'); if ($format) { ($description = $format) =~ s{%([atfglncrdmsqS%])} {$1 eq '%' ? '%' @@ -1495,7 +1503,7 @@ } } - if ((my $basename = $r->dir_config('StreamBase')) && !$self->is_localnet()) { + if ((my $basename = $self->get_config('StreamBase')) && !$self->is_localnet()) { $basename =~ s!http://!http://$auth_info! if $auth_info; return $basename; } @@ -1536,7 +1544,7 @@ sub is_localnet { my $self = shift; return 1 if $self->is_local; # d'uh - my @local = split /\s+/,$self->r->dir_config('LocalNet') or return; + my @local = split /\s+/,$self->get_config('LocalNet') or return; my $remote_ip = $self->r->connection->remote_ip . '.'; foreach (@local) { 1.1 modperl-docs/src/docs/2.0/user/porting/code/apache_mp3_7.diff Index: apache_mp3_7.diff =================================================================== --- Apache/MP3.pm.7 2003-06-06 17:04:27.000000000 +1000 +++ Apache/MP3.pm 2003-06-06 17:13:26.000000000 +1000 @@ -129,7 +129,7 @@ my $self = shift; $self->r->send_http_header( $self->html_content_type ); - return OK if $self->r->header_only; + return Apache::OK if $self->r->header_only; print start_html( -lang => $self->lh->language_tag, @@ -246,20 +246,20 @@ $self->send_playlist([EMAIL PROTECTED]); } - return OK; + return Apache::OK; } # this is called to generate a playlist for selected files if (param('Play Selected')) { - return HTTP_NO_CONTENT unless my @files = param('file'); + return Apache::HTTP_NO_CONTENT unless my @files = param('file'); my $uri = dirname($r->uri); $self->send_playlist([map { "$uri/$_" } @files]); - return OK; + return Apache::OK; } # otherwise don't know how to deal with this $self->r->log_reason('Invalid parameters -- possible attempt to circumvent checks.'); - return FORBIDDEN; + return Apache::FORBIDDEN; } # this generates the top-level directory listing @@ -273,7 +273,7 @@ my $query = $self->r->args; $query = "?" . $query if defined $query; $self->r->header_out(Location => "$uri/$query"); - return REDIRECT; + return Apache::REDIRECT; } return $self->list_directory($dir); @@ -289,9 +289,9 @@ if ($is_audio && !$self->download_ok) { $self->r->log_reason('File downloading is forbidden'); - return FORBIDDEN; + return Apache::FORBIDDEN; } else { - return DECLINED; # allow Apache to do its standard thing + return Apache::DECLINED; # allow Apache to do its standard thing } } @@ -302,17 +302,17 @@ my $self = shift; my $r = $self->r; - return DECLINED unless -e $r->filename; # should be $r->finfo + return Apache::DECLINED unless -e $r->filename; # should be $r->finfo unless ($self->stream_ok) { $r->log_reason('AllowStream forbidden'); - return FORBIDDEN; + return Apache::FORBIDDEN; } if ($self->check_stream_client and !$self->is_stream_client) { my $useragent = $r->header_in('User-Agent'); $r->log_reason("CheckStreamClient is true and $useragent is not a streaming client"); - return FORBIDDEN; + return Apache::FORBIDDEN; } return $self->send_stream($r->filename,$r->uri); @@ -322,12 +322,12 @@ sub send_playlist { my $self = shift; my ($urls,$shuffle) = @_; - return HTTP_NO_CONTENT unless @$urls; + return Apache::HTTP_NO_CONTENT unless @$urls; my $r = $self->r; my $base = $self->stream_base; $r->send_http_header('audio/mpegurl'); - return OK if $r->header_only; + return Apache::OK if $r->header_only; # local user my $local = $self->playlocal_ok && $self->is_local; @@ -377,7 +377,7 @@ $r->print ("$base$_?$stream_parms$CRLF"); } } - return OK; + return Apache::OK; } sub stream_parms { @@ -468,7 +468,7 @@ my $self = shift; my $dir = shift; - return DECLINED unless -d $dir; + return Apache::DECLINED unless -d $dir; my $last_modified = (stat(_))[9]; @@ -478,15 +478,15 @@ my ($time, $ver) = $check =~ /^([a-f0-9]+)-([0-9.]+)$/; if ($check eq '*' or (hex($time) == $last_modified and $ver == $VERSION)) { - return HTTP_NOT_MODIFIED; + return Apache::HTTP_NOT_MODIFIED; } } - return DECLINED unless my ($directories,$mp3s,$playlists,$txtfiles) + return Apache::DECLINED unless my ($directories,$mp3s,$playlists,$txtfiles) = $self->read_directory($dir); $self->r->send_http_header( $self->html_content_type ); - return OK if $self->r->header_only; + return Apache::OK if $self->r->header_only; $self->page_top($dir); $self->directory_top($dir); @@ -514,7 +514,7 @@ print hr unless %$mp3s; print "\n<!-- end main -->\n"; $self->directory_bottom($dir); - return OK; + return Apache::OK; } # print the HTML at the top of the page @@ -1268,8 +1268,8 @@ my $mime = $r->content_type; my $info = $self->fetch_info($file,$mime); - return DECLINED unless $info; # not a legit mp3 file? - my $fh = $self->open_file($file) || return DECLINED; + return Apache::DECLINED unless $info; # not a legit mp3 file? + my $fh = $self->open_file($file) || return Apache::DECLINED; binmode($fh); # to prevent DOS text-mode foolishness my $size = -s $file; @@ -1317,7 +1317,7 @@ $r->print("Content-Length: $size$CRLF"); $r->print("Content-Type: $mime$CRLF"); $r->print("$CRLF"); - return OK if $r->header_only; + return Apache::OK if $r->header_only; if (my $timeout = $self->stream_timeout) { my $seconds = $info->{seconds}; @@ -1330,12 +1330,12 @@ $bytes -= $b; $r->print($data); } - return OK; + return Apache::OK; } # we get here for untimed transmits $r->send_fd($fh); - return OK; + return Apache::OK; } # called to open the MP3 file 1.1 modperl-docs/src/docs/2.0/user/porting/code/apache_mp3_9.diff Index: apache_mp3_9.diff =================================================================== --- Apache/MP3.pm.9 2003-06-06 17:27:45.000000000 +1000 +++ Apache/MP3.pm 2003-06-06 17:55:14.000000000 +1000 @@ -82,8 +82,8 @@ $new->{'r'} ||= $r if $r; my @lang_tags; - push @lang_tags,split /,\s+/,$r->header_in('Accept-language') - if $r->header_in('Accept-language'); + push @lang_tags,split /,\s+/,$r->headers_in->{'Accept-language'} + if $r->headers_in->{'Accept-language'}; push @lang_tags,$new->get_config('DefaultLanguage') || 'en-US'; $new->{'lh'} ||= @@ -272,7 +272,7 @@ my $uri = $self->r->uri; my $query = $self->r->args; $query = "?" . $query if defined $query; - $self->r->header_out(Location => "$uri/$query"); + $self->r->headers_out->{Location} = "$uri/$query"; return Apache::REDIRECT; } @@ -310,7 +310,7 @@ } if ($self->check_stream_client and !$self->is_stream_client) { - my $useragent = $r->header_in('User-Agent'); + my $useragent = $r->headers_in->{'User-Agent'}; $r->log_reason("CheckStreamClient is true and $useragent is not a streaming client"); return Apache::FORBIDDEN; } @@ -472,9 +472,9 @@ my $last_modified = (stat(_))[9]; - $self->r->header_out('ETag' => sprintf("%lx-%s", $last_modified, $VERSION)); + $self->r->headers_out->{'ETag'} = sprintf("%lx-%s", $last_modified, $VERSION); - if (my $check = $self->r->header_in("If-None-Match")) { + if (my $check = $self->r->headers_in->{"If-None-Match"}) { my ($time, $ver) = $check =~ /^([a-f0-9]+)-([0-9.]+)$/; if ($check eq '*' or (hex($time) == $last_modified and $ver == $VERSION)) { @@ -1283,8 +1283,8 @@ my $genre = $info->{genre} || $self->lh->maketext('unknown'); my $range = 0; - $r->header_in("Range") - and $r->header_in("Range") =~ m/bytes=(\d+)/ + $r->headers_in->{"Range"} + and $r->headers_in->{"Range"} =~ m/bytes=(\d+)/ and $range = $1 and seek($fh,$range,0); @@ -1383,11 +1383,11 @@ # return true if client can stream sub is_stream_client { my $r = shift->r; - $r->header_in('Icy-MetaData') # winamp/xmms - || $r->header_in('Bandwidth') # realplayer - || $r->header_in('Accept') =~ m!\baudio/mpeg\b! # mpg123 and others - || $r->header_in('User-Agent') =~ m!^NSPlayer/! # Microsoft media player - || $r->header_in('User-Agent') =~ m!^xmms/!; + $r->headers_in->{'Icy-MetaData'} # winamp/xmms + || $r->headers_in->{'Bandwidth'} # realplayer + || $r->headers_in->{'Accept'} =~ m!\baudio/mpeg\b! # mpg123 and others + || $r->headers_in->{'User-Agent'} =~ m!^NSPlayer/! # Microsoft media player + || $r->headers_in->{'User-Agent'} =~ m!^xmms/!; } # whether to read info for each MP3 file (might take a long time)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]