--- test/html-webhacc/cc.cgi 2007/09/11 08:25:23 1.21 +++ test/html-webhacc/cc.cgi 2007/11/05 09:33:52 1.23 @@ -1,5 +1,6 @@ #!/usr/bin/perl use strict; +use utf8; use lib qw[/home/httpd/html/www/markup/html/whatpm /home/wakaba/work/manakai2/lib]; @@ -88,6 +89,7 @@ my $doc; my $el; + my $manifest; if ($input->{media_type} eq 'text/html') { ($doc, $el) = print_syntax_error_html_section ($input, $result); @@ -102,18 +104,25 @@ }->{$input->{media_type}}) { ($doc, $el) = print_syntax_error_xml_section ($input, $result); print_source_string_section (\($input->{s}), $doc->input_encoding); + } elsif ($input->{media_type} eq 'text/cache-manifest') { +## TODO: MUST be text/cache-manifest + $manifest = print_syntax_error_manifest_section ($input, $result); + print_source_string_section (\($input->{s}), 'utf-8'); } else { ## TODO: Change HTTP status code?? print_result_unknown_type_section ($input); } if (defined $doc or defined $el) { - print_structure_dump_section ($doc, $el); - my $elements = print_structure_error_section ($doc, $el, $result); + print_structure_dump_dom_section ($doc, $el); + my $elements = print_structure_error_dom_section ($doc, $el, $result); print_table_section ($elements->{table}) if @{$elements->{table}}; print_id_section ($elements->{id}) if keys %{$elements->{id}}; print_term_section ($elements->{term}) if keys %{$elements->{term}}; print_class_section ($elements->{class}) if keys %{$elements->{class}}; + } elsif (defined $manifest) { + print_structure_dump_manifest_section ($manifest); + print_structure_error_manifest_section ($manifest, $result); } print_result_section ($result); @@ -134,7 +143,7 @@ ]; - for (qw/decode parse parse_xml check/) { + for (qw/decode parse parse_xml parse_manifest check check_manifest/) { next unless defined $time{$_}; open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; print $file $char_length, "\t", $time{$_}, "\n"; @@ -235,7 +244,8 @@ $type =~ tr/ /-/; $type =~ s/\|/%7C/g; $msg .= qq[ [Description]]; - print STDOUT qq[
$msg
\n]; + print STDOUT qq[
], get_error_level_label (\%opt); + print STDOUT qq[$msg
\n]; add_error ('syntax', \%opt => $result); }; @@ -297,6 +307,41 @@ return ($doc, undef); } # print_syntax_error_xml_section +sub print_syntax_error_manifest_section ($$) { + my ($input, $result) = @_; + + require Whatpm::CacheManifest; + + print STDOUT qq[ +
+

Parse Errors

+ +
]; + push @nav, ['#parse-errors' => 'Parse Error']; + + my $onerror = sub { + my (%opt) = @_; + my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); + print STDOUT qq[
], get_error_label (\%opt), qq[
]; + $type =~ tr/ /-/; + $type =~ s/\|/%7C/g; + $msg .= qq[ [Description]]; + print STDOUT qq[
], get_error_level_label (\%opt); + print STDOUT qq[$msg
\n]; + + add_error ('syntax', \%opt => $result); + }; + + my $time1 = time; + my $manifest = Whatpm::CacheManifest->parse_byte_string + ($input->{s}, $input->{uri}, $input->{base_uri}, $onerror); + $time{parse_manifest} = time - $time1; + + print STDOUT qq[
]; + + return $manifest; +} # print_syntax_error_manifest_section + sub print_source_string_section ($$) { require Encode; my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name @@ -399,7 +444,7 @@ print STDOUT $r; } # print_document_tree -sub print_structure_dump_section ($$) { +sub print_structure_dump_dom_section ($$) { my ($doc, $el) = @_; print STDOUT qq[ @@ -411,9 +456,43 @@ print_document_tree ($el || $doc); print STDOUT qq[]; -} # print_structure_dump_section +} # print_structure_dump_dom_section + +sub print_structure_dump_manifest_section ($) { + my $manifest = shift; + + print STDOUT qq[ +
+

Cache Manifest

+]; + push @nav, ['#dump-manifest' => 'Caceh Manifest']; -sub print_structure_error_section ($$$) { + print STDOUT qq[
Explicit entries
]; + for my $uri (@{$manifest->[0]}) { + my $euri = htescape ($uri); + print STDOUT qq[
<$euri>
]; + } + + print STDOUT qq[
Fallback entries
+ + ]; + for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) { + my $euri = htescape ($uri); + my $euri2 = htescape ($manifest->[1]->{$uri}); + print STDOUT qq[ + ]; + } + + print STDOUT qq[
Oppotunistic Caching NamespaceFallback Entry
<$euri><$euri2>
Online whitelist
]; + for my $uri (@{$manifest->[2]}) { + my $euri = htescape ($uri); + print STDOUT qq[
<$euri>
]; + } + + print STDOUT qq[
]; +} # print_structure_dump_manifest_section + +sub print_structure_error_dom_section ($$$) { my ($doc, $el, $result) = @_; print STDOUT qq[
@@ -429,8 +508,9 @@ $type =~ tr/ /-/; $type =~ s/\|/%7C/g; $msg .= qq[ [Description]]; - print STDOUT qq[
] . get_node_link ($opt{node}) . - qq[
\n
], $msg, "
\n"; + print STDOUT qq[
] . get_error_label (\%opt) . + qq[
\n
], get_error_level_label (\%opt); + print STDOUT $msg, "
\n"; add_error ('structure', \%opt => $result); }; @@ -446,7 +526,31 @@ print STDOUT qq[
]; return $elements; -} # print_structure_error_section +} # print_structure_error_dom_section + +sub print_structure_error_manifest_section ($$$) { + my ($manifest, $result) = @_; + + print STDOUT qq[
+

Document Errors

+ +
]; + push @nav, ['#document-errors' => 'Document Error']; + + require Whatpm::CacheManifest; + Whatpm::CacheManifest->check_manifest ($manifest, sub { + my %opt = @_; + my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}, $opt{node}); + $type =~ tr/ /-/; + $type =~ s/\|/%7C/g; + $msg .= qq[ [Description]]; + print STDOUT qq[
] . get_error_label (\%opt) . + qq[
\n
], $msg, "
\n"; + add_error ('structure', \%opt => $result); + }); + + print STDOUT qq[
]; +} # print_structure_error_manifest_section sub print_table_section ($) { my $tables = shift; @@ -591,10 +695,13 @@ print STDOUT qq[ - -]; + + + + +]; my $must_error = 0; my $should_error = 0; @@ -671,6 +778,64 @@ push @nav, ['#result-summary' => 'Result']; } # print_Result_input_error_section +sub get_error_label ($) { + my $err = shift; + + my $r = ''; + + if (defined $err->{line}) { + if ($err->{column} > 0) { + $r = qq[Line $err->{line} column $err->{column}]; + } else { + $err->{line} = $err->{line} - 1 || 1; + $r = qq[Line $err->{line}]; + } + } + + if (defined $err->{node}) { + $r .= ' ' if length $r; + $r = get_node_link ($err->{node}); + } + + if (defined $err->{index}) { + $r .= ' ' if length $r; + $r .= 'Index ' . (0+$err->{index}); + } + + if (defined $err->{value}) { + $r .= ' ' if length $r; + $r .= '' . htescape ($err->{value}) . ''; + } + + return $r; +} # get_error_label + +sub get_error_level_label ($) { + my $err = shift; + + my $r = ''; + + if (not defined $err->{level} or $err->{level} eq 'm') { + $r = qq[MUST‐level + error: ]; + } elsif ($err->{level} eq 's') { + $r = qq[SHOULD‐level + error: ]; + } elsif ($err->{level} eq 'w') { + $r = qq[Warning: + ]; + } elsif ($err->{level} eq 'unsupported') { + $r = qq[Not + supported: ]; + } else { + my $elevel = htescape ($err->{level}); + $r = qq[$elevel: + ]; + } + + return $r; +} # get_error_level_label + sub get_node_path ($) { my $node = shift; my @r; @@ -819,7 +984,7 @@ if (defined $ct and $ct =~ m#^([0-9A-Za-z._+-]+/[0-9A-Za-z._+-]+)#) { $r->{media_type} = lc $1; } - if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?(\S+)"?/i) { + if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) { $r->{charset} = lc $1; $r->{charset} =~ tr/\\//d; } @@ -919,4 +1084,4 @@ =cut -## $Date: 2007/09/11 08:25:23 $ +## $Date: 2007/11/05 09:33:52 $
MUST-level -ErrorsSHOULD-level -ErrorsWarningsScore
MUST‐level +ErrorsSHOULD‐level +ErrorsWarningsScore