X-Git-Url: https://git.deb.at/?p=deb%2Fpackages.git;a=blobdiff_plain;f=lib%2FPackages%2FCGI.pm;h=beb4e255e9844bc68b4a32006db528e1354e9bd6;hp=b09235273ab4d9e057321f2a9c494287bdf89e09;hb=0c1a44893f94f98deac8435e6ab235228880087f;hpb=1d7c1b6f69a8b6b10fd304730b95eeeaa6654098 diff --git a/lib/Packages/CGI.pm b/lib/Packages/CGI.pm index b092352..beb4e25 100644 --- a/lib/Packages/CGI.pm +++ b/lib/Packages/CGI.pm @@ -4,26 +4,39 @@ use strict; use warnings; use Exporter; -use Packages::Config; our @ISA = qw( Exporter ); -our @EXPORT = qw( DEBUG debug fatal_error ); +our @EXPORT = qw( DEBUG debug fatal_error get_mime ); our @EXPORT_OK = qw( error hint msg note get_all_messages make_url make_search_url ); - # define this to 0 in production mode use constant DEBUG => 1; our $debug = 0; -our (@fatal_errors, @errors, @debug, @msgs, @hints, @notes); +my %mime_types = ( + txt => 'text/plain', + 'txt.gz' => 'text/plain', + html => 'text/html', + rss => 'application/rss+xml', + rfc822 => 'text/plain', + ); + +sub get_mime { + return $mime_types{$_[0]} || $_[1] || 'text/html'; +} + +our (@fatal_errors, @errors, @debug, @hints); +our $http_code; sub reset { - @fatal_errors = @errors = @debug = @msgs = @hints = @notes = (); + @fatal_errors = @errors = @debug = @hints = (); + $http_code = 200; } sub fatal_error { push @fatal_errors, $_[0]; + $http_code = $_[1] if $_[1]; } sub error { push @errors, $_[0]; @@ -35,27 +48,17 @@ sub debug { my $lvl = $_[1] || 0; push(@debug, $_[0]) if $debug > $lvl; } -sub msg { - push @msgs, $_[0]; -} -sub note { - push @notes, [ @_ ]; -} sub get_errors { (@fatal_errors, @errors) } sub get_debug { return unless $debug && @debug; return @debug; } -sub get_msgs { @msgs }; sub get_hints { @hints }; -sub get_notes { @notes }; sub get_all_messages { return { errors => [ @fatal_errors, @errors ], debugs => $debug ? \@debug : [], - msgs => \@msgs, hints => \@hints, - notes => \@notes, }; } @@ -85,7 +88,7 @@ sub parse_params { foreach my $param ( keys %params ) { - debug( "Param $param", 2 ) if DEBUG; + debug( "Param $param", 2 ) if DEBUG; my $p_value_orig = $cgi->param($param); @@ -335,8 +338,8 @@ sub printindexline { sub string2id { my $string = "@_"; - - $string =~ s/[^\w]/_/g; + + $string =~ s/[^\w:.-]/_/g; return $string; }