From 10ca9fdb84594f2144bfd8925d384ec9016cd940 Mon Sep 17 00:00:00 2001 From: josch Date: Tue, 1 Apr 2008 16:16:04 +0000 Subject: [PATCH] fixed 404 error when video isnt there git-svn-id: http://yolanda.mister-muffin.de/svn@258 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/download.pl | 75 ++++++++++++++++++++++-------------------- trunk/functions.pl | 17 ++++------ trunk/index.pl | 2 +- trunk/locale/en-us.xml | 1 + trunk/video.pl | 9 +++-- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/trunk/download.pl b/trunk/download.pl index fce119b..88940f6 100644 --- a/trunk/download.pl +++ b/trunk/download.pl @@ -50,58 +50,61 @@ if($query->param('id')) } #in both cases - do some slurp-eaze to the browser - #TODO: lol insecure! - open(FILE, "<$root/videos/".$query->param('id')); + $file = open(FILE, "<$root/videos/$videoid"); - $filesize = -s "$root/videos/".$query->param('id'); - $range = $query->http('range'); - $range =~ s/bytes=([0-9]+)-/$1/; - - #if a specific range is requested send http partial content headers and seek in the inputfile - if($range) + if($file) { - #if $range is equal or more than filesize throw http 416 header - if($range >= $filesize) + $filesize = -s "$root/videos/".$query->param('id'); + $range = $query->http('range'); + $range =~ s/bytes=([0-9]+)-/$1/; + + #if a specific range is requested send http partial content headers and seek in the inputfile + if($range) { - print $query->header(-status=>'416 Requested Range Not Satisfiable'); + #if $range is equal or more than filesize throw http 416 header + if($range >= $filesize) + { + print $query->header(-status=>'416 Requested Range Not Satisfiable'); + } + else + { + print $query->header(-type=>'application/ogg', + -content_length=> $filesize-$range, + -status=>'206 Partial Content', + -attachment=>$title.".ogv", + -accept_ranges=> "bytes", + -content_range=> "bytes $range-".($filesize-1)."/$filesize" + ); + + seek FILE, $range, 0; + } } else { print $query->header(-type=>'application/ogg', - -content_length=> $filesize-$range, - -status=>'206 Partial Content', - -attachment=>$title.".ogv", - -accept_ranges=> "bytes", - -content_range=> "bytes $range-".($filesize-1)."/$filesize" + -content_length=> $filesize, + -attachment=>$title.".ogv" ); - - seek FILE, $range, 0; } + + while (my $BytesRead = read (FILE, $buff, 8192)) + { + print $buff; + } + close(FILE); } else { - print $query->header(-type=>'application/ogg', - -content_length=> $filesize, - -attachment=>$title.".ogv" - ); + print $session->header( + -status=>'500 Internal Server Error' + ) } - - while (my $BytesRead = read (FILE, $buff, 8192)) - { - print $buff; - } - close(FILE); } else { - @userinfo = get_userinfo_from_sid($session->id); - - @page = get_page_array(@userinfo); - - $page->{'message'}->{'type'} = "error"; - $page->{'message'}->{'text'} = "error_202c"; - - print output_page(); + print $session->header( + -status=>'404 Not found' + ) } } else diff --git a/trunk/functions.pl b/trunk/functions.pl index cdaa0e6..bf2ddcf 100644 --- a/trunk/functions.pl +++ b/trunk/functions.pl @@ -166,13 +166,11 @@ sub output_page -charset=>'UTF-8', -cookie=>@cookies ), - $parser->parse_string( - XMLout( - $page, - KeyAttr => {}, - RootName => 'page' - ) - )->toString; + XMLout( + $page, + KeyAttr => {}, + RootName => 'page' + ); } else { @@ -187,9 +185,6 @@ sub output_page my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath)); - # TODO: this usage of libxsl omits the xsl:output definition (no ident of html) but outputs in UTF8 - # TODO: later versions of XML::LibXSLT (>= 1.62) define output_as_bytes - this is what we want to use - # TODO: wait for debian packagers to update to 1.62 or later $output = $stylesheet->transform( $parser->parse_string( XMLout( @@ -209,6 +204,7 @@ sub output_page -cookie=>@cookies ), $output->toString; + #$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62) } elsif($param_xslt eq "pr0n") { @@ -225,6 +221,7 @@ sub output_page -cookie=>@cookies ), $output->toString; + #$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62) } } } diff --git a/trunk/index.pl b/trunk/index.pl index b7f389c..43dfdb2 100644 --- a/trunk/index.pl +++ b/trunk/index.pl @@ -9,7 +9,7 @@ $session = new CGI::Session; @page = get_page_array(@userinfo); -$page->{frontpage} = ['']; +$page->{frontpage} = ['']; if($query->param('information')) { diff --git a/trunk/locale/en-us.xml b/trunk/locale/en-us.xml index 0688777..3ae76ae 100755 --- a/trunk/locale/en-us.xml +++ b/trunk/locale/en-us.xml @@ -60,6 +60,7 @@ Please repeat your password. You passed no query string. Your browser does not support Ogg Theora video playback. + There is no video matching your request diff --git a/trunk/video.pl b/trunk/video.pl index 63d89dd..db33d21 100644 --- a/trunk/video.pl +++ b/trunk/video.pl @@ -18,7 +18,7 @@ if($query->url_param('action') eq 'bookmark' and $query->url_param('id')) $page->{'message'}->{'type'} = "information"; } #check if id or title is passed -elsif($query->url_param('title') or $query->url_param('id')) +if($query->url_param('title') or $query->url_param('id')) { if($query->url_param('id')) { @@ -67,8 +67,7 @@ elsif($query->url_param('title') or $query->url_param('id')) { #still no results #there is nothing we can do now - this video doesn't exist... - $page->{'message'}->{'type'} = "error"; - $page->{'message'}->{'text'} = "error_202c"; + print $query->redirect("/index.pl?error=error_no_video"); } elsif($rowcount == 1) { @@ -249,6 +248,7 @@ elsif($query->url_param('title') or $query->url_param('id')) 'referer' => $referer }; } + print output_page(); } else { @@ -260,6 +260,5 @@ else { $page->{'message'}->{'type'} = "error"; $page->{'message'}->{'text'} = "error_202c"; + print output_page(); } - -print output_page();