--- test/html-webhacc/cc.cgi 2007/09/11 08:25:23 1.21 +++ test/html-webhacc/cc.cgi 2007/11/11 06:57:16 1.24 @@ -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); + print_result_unknown_type_section ($input, $result); } 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,8 @@ ]; - for (qw/decode parse parse_xml check/) { + for (qw/decode parse parse_html 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"; @@ -209,13 +219,7 @@ require Encode; require Whatpm::HTML; - - $input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. - my $time1 = time; - my $t = Encode::decode ($input->{charset}, $input->{s}); - $time{decode} = time - $time1; - print STDOUT qq[

Parse Errors

@@ -235,23 +239,32 @@ $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; my $el; - $time1 = time; if (defined $inner_html_element and length $inner_html_element) { + $input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. + my $time1 = time; + my $t = Encode::decode ($input->{charset}, $input->{s}); + $time{decode} = time - $time1; + $el = $doc->create_element_ns ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); + $time1 = time; Whatpm::HTML->set_inner_html ($el, $t, $onerror); + $time{parse} = time - $time1; } else { - Whatpm::HTML->parse_string ($t => $doc, $onerror); + my $time1 = time; + Whatpm::HTML->parse_byte_string + ($input->{charset}, $input->{s} => $doc, $onerror); + $time{parse_html} = time - $time1; } - $time{parse} = time - $time1; - + print STDOUT qq[
]; return ($doc, $el); @@ -297,6 +310,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 +447,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 +459,43 @@ print_document_tree ($el || $doc); print STDOUT qq[]; -} # print_structure_dump_section +} # print_structure_dump_dom_section -sub print_structure_error_section ($$$) { +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[
@@ -429,8 +511,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 +529,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 +698,13 @@ print STDOUT qq[ - -]; + + + + +]; my $must_error = 0; my $should_error = 0; @@ -652,15 +762,28 @@ push @nav, ['#result-summary' => 'Result']; } # print_result_section -sub print_result_unknown_type_section ($) { - my $input = shift; +sub print_result_unknown_type_section ($$) { + my ($input, $result) = @_; + my $euri = htescape ($input->{uri}); print STDOUT qq[ -
-

Media type @{[htescape $input->{media_type}]} is not supported!

+
+

Errors

+ +
+
<$euri>
+
Not + supported: + Media type + @{[htescape $input->{media_type}]} + is not supported.
+
]; - push @nav, ['#result-summary' => 'Result']; + push @nav, ['#parse-errors' => 'Errors']; + add_error (char => {level => 'unsupported'} => $result); + add_error (syntax => {level => 'unsupported'} => $result); + add_error (structure => {level => 'unsupported'} => $result); } # print_result_unknown_type_section sub print_result_input_error_section ($) { @@ -671,6 +794,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 +1000,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 +1100,4 @@ =cut -## $Date: 2007/09/11 08:25:23 $ +## $Date: 2007/11/11 06:57:16 $
MUST-level -ErrorsSHOULD-level -ErrorsWarningsScore
MUST‐level +ErrorsSHOULD‐level +ErrorsWarningsScore