--- test/html-webhacc/cc.cgi 2007/09/02 08:40:49 1.18 +++ 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]; @@ -83,13 +84,15 @@ ]; - print_http_header_section ($input); + my $result = {conforming_min => 1, conforming_max => 1}; + print_http_header_section ($input, $result); my $doc; my $el; + my $manifest; if ($input->{media_type} eq 'text/html') { - ($doc, $el) = print_syntax_error_html_section ($input); + ($doc, $el) = print_syntax_error_html_section ($input, $result); print_source_string_section (\($input->{s}), $input->{charset}); } elsif ({ 'text/xml' => 1, @@ -99,23 +102,30 @@ 'application/xhtml+xml' => 1, 'application/xml' => 1, }->{$input->{media_type}}) { - ($doc, $el) = print_syntax_error_xml_section ($input); + ($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); + 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); } - ## TODO: Show result + print_result_section ($result); } else { print STDOUT qq[]; print_result_input_error_section ($input); @@ -133,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"; @@ -141,8 +151,36 @@ exit; -sub print_http_header_section ($) { - my $input = shift; +sub add_error ($$$) { + my ($layer, $err, $result) = @_; + if (defined $err->{level}) { + if ($err->{level} eq 's') { + $result->{$layer}->{should}++; + $result->{$layer}->{score_min} -= 2; + $result->{conforming_min} = 0; + } elsif ($err->{level} eq 'w' or $err->{level} eq 'g') { + $result->{$layer}->{warning}++; + } elsif ($err->{level} eq 'unsupported') { + $result->{$layer}->{unsupported}++; + $result->{unsupported} = 1; + } else { + $result->{$layer}->{must}++; + $result->{$layer}->{score_max} -= 2; + $result->{$layer}->{score_min} -= 2; + $result->{conforming_min} = 0; + $result->{conforming_max} = 0; + } + } else { + $result->{$layer}->{must}++; + $result->{$layer}->{score_max} -= 2; + $result->{$layer}->{score_min} -= 2; + $result->{conforming_min} = 0; + $result->{conforming_max} = 0; + } +} # add_error + +sub print_http_header_section ($$) { + my ($input, $result) = @_; return unless defined $input->{header_status_code} or defined $input->{header_status_text} or @{$input->{header_field}}; @@ -175,8 +213,8 @@ print STDOUT qq[]; } # print_http_header_section -sub print_syntax_error_html_section ($) { - my $input = shift; +sub print_syntax_error_html_section ($$) { + my ($input, $result) = @_; require Encode; require Whatpm::HTML; @@ -206,7 +244,10 @@ $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); }; my $doc = $dom->create_document; @@ -226,8 +267,8 @@ return ($doc, $el); } # print_syntax_error_html_section -sub print_syntax_error_xml_section ($) { - my $input = shift; +sub print_syntax_error_xml_section ($$) { + my ($input, $result) = @_; require Message::DOM::XMLParserTemp; @@ -244,6 +285,14 @@ print STDOUT qq[
Line $line column ]; print STDOUT $err->location->column_number, "
"; print STDOUT htescape $err->text, "
\n"; + + add_error ('syntax', {type => $err->text, + level => [ + $err->SEVERITY_FATAL_ERROR => 'm', + $err->SEVERITY_ERROR => 'm', + $err->SEVERITY_WARNING => 's', + ]->[$err->severity]} => $result); + return 1; }; @@ -258,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 @@ -360,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[ @@ -372,10 +456,44 @@ print_document_tree ($el || $doc); print STDOUT qq[]; -} # print_structure_dump_section +} # print_structure_dump_dom_section -sub print_structure_error_section ($$) { - my ($doc, $el) = @_; +sub print_structure_dump_manifest_section ($) { + my $manifest = shift; + + print STDOUT qq[ +
+

Cache Manifest

+]; + push @nav, ['#dump-manifest' => 'Caceh Manifest']; + + 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[

Document Errors

@@ -390,8 +508,10 @@ $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); }; my $elements; @@ -406,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; @@ -524,6 +668,97 @@ print STDOUT qq[]; } # print_class_section +sub print_result_section ($) { + my $result = shift; + + print STDOUT qq[ +
+

Result

]; + + if ($result->{unsupported} and $result->{conforming_max}) { + print STDOUT qq[

The conformance + checker cannot decide whether the document is conforming or + not, since the document contains one or more unsupported + features. The document might or might not be conforming.

]; + } elsif ($result->{conforming_min}) { + print STDOUT qq[

No conformance-error is + found in this document.

]; + } elsif ($result->{conforming_max}) { + print STDOUT qq[

This document + is likely non-conforming, but in rare case + it might be conforming.

]; + } else { + print STDOUT qq[

This document is + non-conforming.

]; + } + + print STDOUT qq[ ++ + + + + +]; + + my $must_error = 0; + my $should_error = 0; + my $warning = 0; + my $score_min = 0; + my $score_max = 0; + my $score_base = 20; + my $score_unit = $score_base / 100; + for ( + [Transfer => 'transfer', ''], + [Character => 'char', ''], + [Syntax => 'syntax', '#parse-errors'], + [Structure => 'structure', '#document-errors'], + ) { + $must_error += ($result->{$_->[1]}->{must} += 0); + $should_error += ($result->{$_->[1]}->{should} += 0); + $warning += ($result->{$_->[1]}->{warning} += 0); + $score_min += (($result->{$_->[1]}->{score_min} *= $score_unit) += $score_base); + $score_max += (($result->{$_->[1]}->{score_max} *= $score_unit) += $score_base); + + my $uncertain = $result->{$_->[1]}->{unsupported} ? '?' : ''; + my $label = $_->[0]; + if ($result->{$_->[1]}->{must} or + $result->{$_->[1]}->{should} or + $result->{$_->[1]}->{warning} or + $result->{$_->[1]}->{unsupported}) { + $label = qq[$label]; + } + + print STDOUT qq[]; + if ($uncertain) { + print qq[]; + } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { + print qq[]; + } else { + print qq[]; + } + } + + $score_max += $score_base; + + print STDOUT qq[ + + + + + + + +
MUST‐level +ErrorsSHOULD‐level +ErrorsWarningsScore
$label$result->{$_->[1]}->{must}$uncertain$result->{$_->[1]}->{should}$uncertain$result->{$_->[1]}->{warning}$uncertain−∞..$result->{$_->[1]}->{score_max}$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}
$result->{$_->[1]}->{score_min}
Semantics0?0?0?−∞..$score_base
Total$must_error?$should_error?$warning?−∞..$score_max
+ +

Important: This conformance checking service +is under development. The result above might be wrong.

+
]; + push @nav, ['#result-summary' => 'Result']; +} # print_result_section + sub print_result_unknown_type_section ($) { my $input = shift; @@ -543,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; @@ -691,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; } @@ -791,4 +1084,4 @@ =cut -## $Date: 2007/09/02 08:40:49 $ +## $Date: 2007/11/05 09:33:52 $