--- test/html-webhacc/cc.cgi 2008/07/18 14:44:16 1.52 +++ test/html-webhacc/cc.cgi 2008/07/20 16:53:10 1.54 @@ -6,22 +6,13 @@ /home/wakaba/work/manakai2/lib]; use CGI::Carp qw[fatalsToBrowser]; use Scalar::Util qw[refaddr]; -use Time::HiRes qw/time/; -sub htescape ($) { - my $s = $_[0]; - $s =~ s/&/&/g; - $s =~ s/</g; - $s =~ s/>/>/g; - $s =~ s/"/"/g; - $s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{ - sprintf 'U+%04X', ord $1; - }ge; - return $s; -} # htescape + require WebHACC::Input; + require WebHACC::Result; + require WebHACC::Output; + +my $out; - my @nav; - my %time; require Message::DOM::DOMImplementation; my $dom = Message::DOM::DOMImplementation->new; { @@ -32,13 +23,14 @@ print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; exit; } - - binmode STDOUT, ':utf8'; - $| = 1; - + load_text_catalog ('en'); ## TODO: conneg - print STDOUT qq[Content-Type: text/html; charset=utf-8 + $out = WebHACC::Output->new; + $out->handle (*STDOUT); + $out->set_utf8; + $out->set_flush; + $out->html (qq[Content-Type: text/html; charset=utf-8 @@ -49,170 +41,146 @@
<@{[htescape $input->{request_uri}]}>
<@{[htescape $input->{uri}]}>
+ $out->start_section (id => 'document-info', title => 'Information');
+ $out->html (qq[<@{[htescape $input->{base_uri}]}>
@{[htescape $input->{media_type}]}
- @{[$input->{media_type_overridden} ? '(overridden)' : defined $input->{official_type} ? $input->{media_type} eq $input->{official_type} ? '' : '(sniffed; official type is: '.htescape ($input->{official_type}).'
)' : '(sniffed)']}'.htescape ($input->{charset}).'
' : '(none)']}
- @{[$input->{charset_overridden} ? '(overridden)' : '']}]);
+ $out->text ($input->{media_type});
+ $out->html (qq[
]);
+ if ($input->{media_type_overridden}) {
+ $out->html ('(overridden)');
+ } elsif (defined $input->{official_type}) {
+ if ($input->{media_type} eq $input->{official_type}) {
+ #
+ } else {
+ $out->html ('(sniffed; official type is: ');
+ $out->text ($input->{official_type});
+ $out->html ('
)');
+ }
+ } else {
+ $out->html ('(sniffed)');
+ }
+ $out->html (q[');
+ $out->text ($input->{charset});
+ $out->html ('
');
+ } else {
+ $out->text ('(none)');
+ }
+ $out->html (' overridden') if $input->{charset_overridden};
+ $out->html (qq[
@{[htescape $subinput->{media_type}]}
@@ -258,783 +219,19 @@
Note: Due to the limitation of the -network library in use, the content of this section might -not be the real header.
- -Status code | ]; - print STDOUT qq[@{[htescape ($input->{header_status_code})]} |
---|---|
Status text | ]; - print STDOUT qq[@{[htescape ($input->{header_status_text})]} |
@{[htescape ($_->[0])]} | ];
- print STDOUT qq[@{[htescape ($_->[1])]} |
@{[htescape ($opt{value})]}
)];
- } elsif (defined $opt{token}) {
- print STDOUT qq[ (@{[htescape (Whatpm::CSS::Tokenizer->serialize_token ($opt{token}))]}
)];
- }
- $type =~ tr/ /-/;
- $type =~ s/\|/%7C/g;
- $msg .= qq[ [Description]];
- print STDOUT qq[] . htescape ($child->tag_name) .
- '
'; ## ISSUE: case
-
- if ($child->has_attributes) {
- $r .= '] . htescape ($attr->[0]) . '
= '; ## ISSUE: case?
- $r .= '' . htescape ($attr->[1]) . '
' . htescape ($child->data) . '
<[CDATA[
' . htescape ($child->data) . '
]]>
<!--
' . htescape ($child->data) . '
-->
charset
parameter = ];
- $r .= htescape ($cp) . qq[
inputEncoding
= ];
- my $ie = $child->input_encoding;
- if (defined $ie) {
- $r .= qq[@{[htescape ($ie)]}
];
- if ($child->manakai_has_bom) {
- $r .= qq[ (with BOM
)];
- }
- } else {
- $r .= qq[(null
)];
- }
- $r .= qq[@{[htescape ($child->xml_version)]}
@{[htescape ($child->xml_encoding)]}
<!DOCTYPE>
@{[htescape ($child->name)]}
@{[htescape ($child->public_id)]}
@{[htescape ($child->system_id)]}
<?@{[htescape ($child->target)]}
@{[htescape ($child->data)]}
?>
".htescape ($cssom->css_text).""; - - print STDOUT qq[
<$euri>
Oppotunistic Caching Namespace | -Fallback Entry |
---|---|
<$euri> |
- <$euri2> | ];
- }
-
- print STDOUT qq[
<$euri>
"; - print STDOUT htescape ($idl->idl_text); - print STDOUT ""; - - print STDOUT qq[
<$euri>
];
- my $eccuri = htescape (get_cc_uri ($uri));
- 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[- | MUST‐level -Errors | -SHOULD‐level -Errors | -Warnings | -Score | ||
---|---|---|---|---|---|---|
$label | $result->{$_->[1]}->{must}$uncertain | $result->{$_->[1]}->{should}$uncertain | $result->{$_->[1]}->{warning}$uncertain | ]; - if ($uncertain) { - print qq[−∞..$result->{$_->[1]}->{score_max}]; - } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { - print qq[ | $result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}]; - } else { - print qq[ | $result->{$_->[1]}->{score_min}]; - } - print qq[ / 20]; - } - - $score_max += $score_base; - - print STDOUT qq[ - |
Semantics | 0? | 0? | 0? | −∞..$score_base / 20 - | ||
Total | -$must_error? | -$should_error? | -$warning? | -−∞..$score_max / 100 - |
Important: This conformance checking service -is under development. The result above might be wrong.
-<$euri>
@{[htescape $input->{media_type}]}
- is not supported.Input Error: @{[htescape ($input->{error_status_text})]}
-' . 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 'u' or $err->{level} eq 'unsupported') {
- $r = qq[Not
- supported: ];
- } elsif ($err->{level} eq 'i') {
- $r = qq[Information: ];
- } else {
- my $elevel = htescape ($err->{level});
- $r = qq[$elevel:
- ];
- }
-
- return $r;
-} # get_error_level_label
-
-sub get_node_path ($) {
- my $node = shift;
- my @r;
- while (defined $node) {
- my $rs;
- if ($node->node_type == 1) {
- $rs = $node->node_name;
- $node = $node->parent_node;
- } elsif ($node->node_type == 2) {
- $rs = '@' . $node->node_name;
- $node = $node->owner_element;
- } elsif ($node->node_type == 3) {
- $rs = '"' . $node->data . '"';
- $node = $node->parent_node;
- } elsif ($node->node_type == 9) {
- @r = ('') unless @r;
- $rs = '';
- $node = $node->parent_node;
- } else {
- $rs = '#' . $node->node_type;
- $node = $node->parent_node;
- }
- unshift @r, $rs;
- }
- return join '/', @r;
-} # get_node_path
-
-sub get_node_link ($$) {
- return qq[] .
- htescape (get_node_path ($_[1])) . qq[];
-} # get_node_link
-
{
my $Msg = {};
sub load_text_catalog ($) {
+# my $self = shift;
my $lang = shift; # MUST be a canonical lang name
open my $file, '<:utf8', "cc-msg.$lang.txt"
or die "$0: cc-msg.$lang.txt: $!";
@@ -1478,7 +380,8 @@
}
} # load_text_catalog
-sub get_text ($) {
+sub get_text ($;$$) {
+# my $self = shift;
my ($type, $level, $node) = @_;
$type = $level . ':' . $type if defined $level;
$level = 'm' unless defined $level;
@@ -1487,24 +390,24 @@
if (defined $Msg->{$type}) {
my $msg = $Msg->{$type}->[1];
$msg =~ s{\$([0-9]+)}{
- defined $arg[$1] ? htescape ($arg[$1]) : '(undef)';
- }ge;
+ defined $arg[$1] ? ($arg[$1]) : '(undef)';
+ }ge; ##BUG: ^ must be escaped
$msg =~ s{{\@([A-Za-z0-9:_.-]+)}}{
UNIVERSAL::can ($node, 'get_attribute_ns')
- ? htescape ($node->get_attribute_ns (undef, $1)) : ''
- }ge;
- $msg =~ s{{\@}}{
- UNIVERSAL::can ($node, 'value') ? htescape ($node->value) : ''
+ ? ($node->get_attribute_ns (undef, $1)) : ''
+ }ge; ## BUG: ^ must be escaped
+ $msg =~ s{{\@}}{ ## BUG: v must be escaped
+ UNIVERSAL::can ($node, 'value') ? ($node->value) : ''
}ge;
$msg =~ s{{local-name}}{
UNIVERSAL::can ($node, 'manakai_local_name')
- ? htescape ($node->manakai_local_name) : ''
- }ge;
+ ? ($node->manakai_local_name) : ''
+ }ge; ## BUG: ^ must be escaped
$msg =~ s{{element-local-name}}{
(UNIVERSAL::can ($node, 'owner_element') and
$node->owner_element)
- ? htescape ($node->owner_element->manakai_local_name)
- : ''
+ ? ($node->owner_element->manakai_local_name)
+ : '' ## BUG: ^ must be escaped
}ge;
return ($type, 'level-' . $level . ' ' . $Msg->{$type}->[0], $msg);
} elsif ($type =~ s/:([^:]*)$//) {
@@ -1512,34 +415,27 @@
redo;
}
}
- return ($type, 'level-'.$level, htescape ($_[0]));
+ return ($type, 'level-'.$level, ($_[0]));
+ ## BUG: ^ must be escaped
} # get_text
}
-sub encode_uri_component ($) {
- require Encode;
- my $s = Encode::encode ('utf8', shift);
- $s =~ s/([^0-9A-Za-z_.~-])/sprintf '%%%02X', ord $1/ge;
- return $s;
-} # encode_uri_component
-
-sub get_cc_uri ($) {
- return './?uri=' . encode_uri_component ($_[0]);
-} # get_cc_uri
-
sub get_input_document ($$) {
my ($http, $dom) = @_;
- my $request_uri = $http->get_parameter ('uri');
- my $r = {};
+ require Encode;
+ my $request_uri = Encode::decode ('utf-8', $http->get_parameter ('uri'));
+ my $r = WebHACC::Input->new;
if (defined $request_uri and length $request_uri) {
my $uri = $dom->create_uri_reference ($request_uri);
unless ({
http => 1,
}->{lc $uri->uri_scheme}) {
- return {uri => $request_uri, request_uri => $request_uri,
- error_status_text => 'URI scheme not allowed'};
+ $r = WebHACC::Input::Error->new;
+ $r->{uri} = $request_uri;
+ $r->{request_uri} = $request_uri;
+ $r->{error_status_text} = 'URL scheme not allowed';
}
require Message::Util::HostPermit;
@@ -1566,8 +462,11 @@
Allow host=*
EOH
unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) {
- return {uri => $request_uri, request_uri => $request_uri,
- error_status_text => 'Connection to the host is forbidden'};
+ my $r = WebHACC::Input::Error->new;
+ $r->{uri} = $request_uri;
+ $r->{request_uri} = $request_uri;
+ $r->{error_status_text} = 'Connection to the host is forbidden';
+ return $r;
}
require LWP::UserAgent;
@@ -1717,4 +616,4 @@
=cut
-## $Date: 2008/07/18 14:44:16 $
+## $Date: 2008/07/20 16:53:10 $