| 2 |
use strict; |
use strict; |
| 3 |
|
|
| 4 |
use lib qw[/home/httpd/html/www/markup/html/whatpm |
use lib qw[/home/httpd/html/www/markup/html/whatpm |
| 5 |
/home/wakaba/work/manakai/lib |
/home/wakaba/work/manakai2/lib]; |
|
/home/wakaba/public_html/-temp/wiki/lib]; |
|
| 6 |
use CGI::Carp qw[fatalsToBrowser]; |
use CGI::Carp qw[fatalsToBrowser]; |
|
use Scalar::Util qw[refaddr]; |
|
| 7 |
|
|
| 8 |
use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module |
require WebHACC::Input; |
| 9 |
|
|
| 10 |
sub htescape ($) { |
{ |
| 11 |
my $s = $_[0]; |
require Message::CGI::HTTP; |
| 12 |
$s =~ s/&/&/g; |
my $http = Message::CGI::HTTP->new; |
|
$s =~ s/</</g; |
|
|
$s =~ s/>/>/g; |
|
|
$s =~ s/"/"/g; |
|
|
$s =~ s!([\x00-\x09\x0B-\x1F\x7F-\x80])!sprintf '<var>U+%04X</var>', ord $1!ge; |
|
|
return $s; |
|
|
} # htescape |
|
|
|
|
|
my $http = SuikaWiki::Input::HTTP->new; |
|
| 13 |
|
|
| 14 |
## TODO: _charset_ |
require WebHACC::Output; |
| 15 |
|
my $out = WebHACC::Output->new; |
| 16 |
|
$out->handle (*STDOUT); |
| 17 |
|
$out->set_utf8; |
| 18 |
|
|
| 19 |
if ($http->meta_variable ('PATH_INFO') ne '/') { |
if ($http->get_meta_variable ('PATH_INFO') ne '/') { |
| 20 |
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; |
$out->http_error (404); |
| 21 |
exit; |
exit; |
| 22 |
} |
} |
| 23 |
|
|
|
require Message::DOM::DOMImplementation; |
|
|
my $dom = Message::DOM::DOMImplementation->new; |
|
|
|
|
|
my $input = get_input_document ($http, $dom); |
|
|
my $inner_html_element = $http->parameter ('e'); |
|
|
|
|
| 24 |
load_text_catalog ('en'); ## TODO: conneg |
load_text_catalog ('en'); ## TODO: conneg |
| 25 |
|
|
| 26 |
my @nav; |
$out->set_flush; |
| 27 |
print STDOUT qq[Content-Type: text/html; charset=utf-8 |
$out->http_header; |
| 28 |
|
$out->html_header; |
| 29 |
|
$out->unset_flush; |
| 30 |
|
|
| 31 |
|
my $input = get_input_document ($http); |
| 32 |
|
$out->input ($input); |
| 33 |
|
|
| 34 |
|
require WebHACC::Result; |
| 35 |
|
my $result = WebHACC::Result->new; |
| 36 |
|
$result->output ($out); |
| 37 |
|
$result->{conforming_min} = 1; |
| 38 |
|
$result->{conforming_max} = 1; |
| 39 |
|
|
| 40 |
<!DOCTYPE html> |
$out->html ('<script src="../cc-script.js"></script>'); |
|
<html lang="en"> |
|
|
<head> |
|
|
<title>Web Document Conformance Checker (BETA)</title> |
|
|
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
|
|
</head> |
|
|
<body> |
|
|
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
|
|
|
|
|
<div id="document-info" class="section"> |
|
|
<dl> |
|
|
<dt>Request URI</dt> |
|
|
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>></code></dd> |
|
|
<dt>Document URI</dt> |
|
|
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{uri}]}">@{[htescape $input->{uri}]}</a>></code></dd> |
|
|
]; # no </dl> yet |
|
|
push @nav, ['#document-info' => 'Information']; |
|
|
|
|
|
if (defined $input->{s}) { |
|
|
|
|
|
print STDOUT qq[ |
|
|
<dt>Base URI</dt> |
|
|
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>></code></dd> |
|
|
<dt>Internet Media Type</dt> |
|
|
<dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> |
|
|
@{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
|
|
<dt>Character Encoding</dt> |
|
|
<dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']} |
|
|
@{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
|
|
</dl> |
|
|
</div> |
|
|
]; |
|
|
|
|
|
print_http_header_section ($input); |
|
|
|
|
|
my $doc; |
|
|
my $el; |
|
|
|
|
|
if ($input->{media_type} eq 'text/html') { |
|
|
require Encode; |
|
|
require Whatpm::HTML; |
|
|
|
|
|
my $t = Encode::decode ($input->{charset}, $input->{s}); |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Parse Errors</h2> |
|
|
|
|
|
<dl> |
|
|
]; |
|
|
push @nav, ['#parse-errors' => 'Parse Error']; |
|
|
|
|
|
my $onerror = sub { |
|
|
my (%opt) = @_; |
|
|
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
|
|
if ($opt{column} > 0) { |
|
|
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n]; |
|
|
} else { |
|
|
$opt{line} = $opt{line} - 1 || 1; |
|
|
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n]; |
|
|
} |
|
|
$opt{type} =~ tr/ /-/; |
|
|
$opt{type} =~ s/\|/%7C/g; |
|
|
$msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]]; |
|
|
print STDOUT qq[<dd class="$cls">$msg</dd>\n]; |
|
|
}; |
|
|
|
|
|
$doc = $dom->create_document; |
|
|
if (defined $inner_html_element and length $inner_html_element) { |
|
|
$el = $doc->create_element_ns |
|
|
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
|
|
Whatpm::HTML->set_inner_html ($el, $t, $onerror); |
|
|
} else { |
|
|
Whatpm::HTML->parse_string ($t => $doc, $onerror); |
|
|
} |
|
|
|
|
|
print STDOUT qq[ |
|
|
</dl> |
|
|
</div> |
|
|
]; |
|
|
|
|
|
print_source_string_section (\($input->{s}), $input->{charset}); |
|
|
} elsif ({ |
|
|
'text/xml' => 1, |
|
|
'application/xhtml+xml' => 1, |
|
|
'application/xml' => 1, |
|
|
}->{$input->{media_type}}) { |
|
|
require Message::DOM::XMLParserTemp; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Parse Errors</h2> |
|
|
|
|
|
<dl>]; |
|
|
push @nav, ['#parse-errors' => 'Parse Error']; |
|
|
|
|
|
my $onerror = sub { |
|
|
my $err = shift; |
|
|
my $line = $err->location->line_number; |
|
|
print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ]; |
|
|
print STDOUT $err->location->column_number, "</dt><dd>"; |
|
|
print STDOUT htescape $err->text, "</dd>\n"; |
|
|
return 1; |
|
|
}; |
|
|
|
|
|
open my $fh, '<', \($input->{s}); |
|
|
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
|
|
($fh => $dom, $onerror, charset => $input->{charset}); |
|
|
|
|
|
print STDOUT qq[</dl> |
|
|
</div> |
|
|
|
|
|
]; |
|
|
print_source_string_section (\($input->{s}), $doc->input_encoding); |
|
|
} else { |
|
|
## TODO: Change HTTP status code?? |
|
|
print STDOUT qq[ |
|
|
<div id="result-summary" class="section"> |
|
|
<p><em>Media type <code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> is not supported!</em></p> |
|
|
</div> |
|
|
]; |
|
|
push @nav, ['#result-summary' => 'Result']; |
|
|
} |
|
| 41 |
|
|
| 42 |
|
check_and_print ($input => $result => $out); |
|
if (defined $doc or defined $el) { |
|
|
print STDOUT qq[ |
|
|
<div id="document-tree" class="section"> |
|
|
<h2>Document Tree</h2> |
|
|
]; |
|
|
push @nav, ['#document-tree' => 'Tree']; |
|
|
|
|
|
print_document_tree ($el || $doc); |
|
|
|
|
|
print STDOUT qq[ |
|
|
</div> |
|
|
|
|
|
<div id="document-errors" class="section"> |
|
|
<h2>Document Errors</h2> |
|
|
|
|
|
<dl>]; |
|
|
push @nav, ['#document-errors' => 'Document Error']; |
|
|
|
|
|
require Whatpm::ContentChecker; |
|
|
my $onerror = sub { |
|
|
my %opt = @_; |
|
|
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
|
|
$opt{type} = $opt{level} . ':' . $opt{type} if defined $opt{level}; |
|
|
$opt{type} =~ tr/ /-/; |
|
|
$opt{type} =~ s/\|/%7C/g; |
|
|
$msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]]; |
|
|
print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) . |
|
|
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
|
|
}; |
|
|
|
|
|
my $elements; |
|
|
if ($el) { |
|
|
$elements = Whatpm::ContentChecker->check_element ($el, $onerror); |
|
|
} else { |
|
|
$elements = Whatpm::ContentChecker->check_document ($doc, $onerror); |
|
|
} |
|
|
|
|
|
print STDOUT qq[</dl> |
|
|
</div> |
|
|
]; |
|
|
|
|
|
if (@{$elements->{table}}) { |
|
|
require JSON; |
|
|
|
|
|
print STDOUT qq[ |
|
|
<div id="tables" class="section"> |
|
|
<h2>Tables</h2> |
|
|
|
|
|
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]--> |
|
|
<script src="../table-script.js" type="text/javascript"></script> |
|
|
<noscript> |
|
|
<p><em>Structure of tables are visualized here if scripting is enabled.</em></p> |
|
|
</noscript> |
|
|
]; |
|
|
|
|
|
my $i = 0; |
|
|
for my $table_el (@{$elements->{table}}) { |
|
|
$i++; |
|
|
print STDOUT qq[<div class="section" id="table-$i"><h3>] . |
|
|
get_node_link ($table_el) . q[</h3>]; |
|
|
|
|
|
my $table = Whatpm::HTMLTable->form_table ($table_el); |
|
|
|
|
|
for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) { |
|
|
next unless $_; |
|
|
delete $_->{element}; |
|
|
} |
|
|
|
|
|
for (@{$table->{row_group}}) { |
|
|
next unless $_; |
|
|
next unless $_->{element}; |
|
|
$_->{type} = $_->{element}->manakai_local_name; |
|
|
delete $_->{element}; |
|
|
} |
|
|
|
|
|
for (@{$table->{cell}}) { |
|
|
next unless $_; |
|
|
for (@{$_}) { |
|
|
next unless $_; |
|
|
for (@$_) { |
|
|
$_->{id} = refaddr $_->{element} if defined $_->{element}; |
|
|
delete $_->{element}; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
print STDOUT '</div><script type="text/javascript">tableToCanvas ('; |
|
|
print STDOUT JSON::objToJson ($table); |
|
|
print STDOUT qq[, document.getElementById ('table-$i'));</script>]; |
|
|
} |
|
|
|
|
|
print STDOUT qq[</div>]; |
|
|
} |
|
|
|
|
|
if (keys %{$elements->{term}}) { |
|
|
print STDOUT qq[ |
|
|
<div id="terms" class="section"> |
|
|
<h2>Terms</h2> |
|
|
|
|
|
<dl> |
|
|
]; |
|
|
for my $term (sort {$a cmp $b} keys %{$elements->{term}}) { |
|
|
print STDOUT qq[<dt>@{[htescape $term]}</dt>]; |
|
|
for (@{$elements->{term}->{$term}}) { |
|
|
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
|
|
} |
|
|
} |
|
|
print STDOUT qq[</dl></div>]; |
|
|
} |
|
|
} |
|
|
|
|
|
## TODO: Show result |
|
|
} else { |
|
|
print STDOUT qq[ |
|
|
</dl> |
|
|
</div> |
|
|
|
|
|
<div class="section" id="result-summary"> |
|
|
<p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p> |
|
|
</div> |
|
|
]; |
|
|
push @nav, ['#result-summary' => 'Result']; |
|
|
|
|
|
} |
|
|
|
|
|
print STDOUT qq[ |
|
|
<ul class="navigation" id="nav-items"> |
|
|
]; |
|
|
for (@nav) { |
|
|
print STDOUT qq[<li><a href="$_->[0]">$_->[1]</a></li>]; |
|
|
} |
|
|
print STDOUT qq[ |
|
|
</ul> |
|
|
</body> |
|
|
</html> |
|
|
]; |
|
|
|
|
|
exit; |
|
|
|
|
|
sub print_http_header_section ($) { |
|
|
my $input = shift; |
|
|
return unless defined $input->{header_status_code} or |
|
|
defined $input->{header_status_text} or |
|
|
@{$input->{header_field}}; |
|
|
|
|
|
push @nav, ['#source-header' => 'HTTP Header']; |
|
|
print STDOUT qq[<div id="source-header" class="section"> |
|
|
<h2>HTTP Header</h2> |
|
|
|
|
|
<p><strong>Note</strong>: Due to the limitation of the |
|
|
network library in use, the content of this section might |
|
|
not be the real header.</p> |
|
|
|
|
|
<table><tbody> |
|
|
]; |
|
|
|
|
|
if (defined $input->{header_status_code}) { |
|
|
print STDOUT qq[<tr><th scope="row">Status code</th>]; |
|
|
print STDOUT qq[<td><code>@{[htescape ($input->{header_status_code})]}</code></td></tr>]; |
|
|
} |
|
|
if (defined $input->{header_status_text}) { |
|
|
print STDOUT qq[<tr><th scope="row">Status text</th>]; |
|
|
print STDOUT qq[<td><code>@{[htescape ($input->{header_status_text})]}</code></td></tr>]; |
|
|
} |
|
| 43 |
|
|
| 44 |
for (@{$input->{header_field}}) { |
$result->generate_result_section; |
|
print STDOUT qq[<tr><th scope="row"><code>@{[htescape ($_->[0])]}</code></th>]; |
|
|
print STDOUT qq[<td><code>@{[htescape ($_->[1])]}</code></td></tr>]; |
|
|
} |
|
|
|
|
|
print STDOUT qq[</tbody></table></div>]; |
|
|
} # print_http_header_section |
|
|
|
|
|
sub print_source_string_section ($$) { |
|
|
require Encode; |
|
|
my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name |
|
|
return unless $enc; |
|
|
|
|
|
my $s = \($enc->decode (${$_[0]})); |
|
|
my $i = 1; |
|
|
push @nav, ['#source-string' => 'Source']; |
|
|
print STDOUT qq[<div id="source-string" class="section"> |
|
|
<h2>Document Source</h2> |
|
|
<ol lang="">\n]; |
|
|
if (length $$s) { |
|
|
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
|
|
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
|
|
$i++; |
|
|
} |
|
|
if ($$s =~ /\G([^\x0A]+)/gc) { |
|
|
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
|
|
} |
|
|
} else { |
|
|
print STDOUT q[<li id="line-1"></li>]; |
|
|
} |
|
|
print STDOUT "</ol></div>"; |
|
|
} # print_input_string_section |
|
| 45 |
|
|
| 46 |
sub print_document_tree ($) { |
$out->nav_list; |
|
my $node = shift; |
|
|
my $r = '<ol class="xoxo">'; |
|
|
|
|
|
my @node = ($node); |
|
|
while (@node) { |
|
|
my $child = shift @node; |
|
|
unless (ref $child) { |
|
|
$r .= $child; |
|
|
next; |
|
|
} |
|
| 47 |
|
|
| 48 |
my $node_id = 'node-'.refaddr $child; |
exit; |
| 49 |
my $nt = $child->node_type; |
} |
|
if ($nt == $child->ELEMENT_NODE) { |
|
|
my $child_nsuri = $child->namespace_uri; |
|
|
$r .= qq[<li id="$node_id" class="tree-element"><code title="@{[defined $child_nsuri ? $child_nsuri : '']}">] . htescape ($child->tag_name) . |
|
|
'</code>'; ## ISSUE: case |
|
|
|
|
|
if ($child->has_attributes) { |
|
|
$r .= '<ul class="attributes">'; |
|
|
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
|
|
@{$child->attributes}) { |
|
|
$r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $_->[2] ? $_->[2] : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
|
|
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
|
|
} |
|
|
$r .= '</ul>'; |
|
|
} |
|
| 50 |
|
|
| 51 |
if ($child->has_child_nodes) { |
sub check_and_print ($$$) { |
| 52 |
$r .= '<ol class="children">'; |
my ($input, $result, $out) = @_; |
| 53 |
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
my $original_input = $out->input; |
| 54 |
} else { |
$out->input ($input); |
| 55 |
$r .= '</li>'; |
|
| 56 |
} |
$input->generate_info_section ($result); |
| 57 |
} elsif ($nt == $child->TEXT_NODE) { |
|
| 58 |
$r .= qq'<li id="$node_id" class="tree-text"><q lang="">' . htescape ($child->data) . '</q></li>'; |
$input->generate_transfer_sections ($result); |
| 59 |
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
|
| 60 |
$r .= qq'<li id="$node_id" class="tree-cdata"><code><[CDATA[</code><q lang="">' . htescape ($child->data) . '</q><code>]]></code></li>'; |
unless (defined $input->{s}) { |
| 61 |
} elsif ($nt == $child->COMMENT_NODE) { |
$result->{conforming_min} = 0; |
| 62 |
$r .= qq'<li id="$node_id" class="tree-comment"><code><!--</code><q lang="">' . htescape ($child->data) . '</q><code>--></code></li>'; |
return; |
| 63 |
} elsif ($nt == $child->DOCUMENT_NODE) { |
} |
| 64 |
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
|
| 65 |
$r .= qq[<ul class="attributes">]; |
my $checker_class = { |
| 66 |
$r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>]; |
'text/cache-manifest' => 'WebHACC::Language::CacheManifest', |
| 67 |
$r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>]; |
'text/css' => 'WebHACC::Language::CSS', |
| 68 |
unless ($child->manakai_is_html) { |
'text/html' => 'WebHACC::Language::HTML', |
| 69 |
$r .= qq[<li>XML version = <code>@{[htescape ($child->xml_version)]}</code></li>]; |
'text/x-webidl' => 'WebHACC::Language::WebIDL', |
| 70 |
if (defined $child->xml_encoding) { |
|
| 71 |
$r .= qq[<li>XML encoding = <code>@{[htescape ($child->xml_encoding)]}</code></li>]; |
'text/xml' => 'WebHACC::Language::XML', |
| 72 |
} else { |
'application/atom+xml' => 'WebHACC::Language::XML', |
| 73 |
$r .= qq[<li>XML encoding = (null)</li>]; |
'application/rss+xml' => 'WebHACC::Language::XML', |
| 74 |
} |
'image/svg+xml' => 'WebHACC::Language::XML', |
| 75 |
$r .= qq[<li>XML standalone = @{[$child->xml_standalone ? 'true' : 'false']}</li>]; |
'application/xhtml+xml' => 'WebHACC::Language::XML', |
| 76 |
} |
'application/xml' => 'WebHACC::Language::XML', |
| 77 |
$r .= qq[</ul>]; |
## TODO: Should we make all XML MIME Types fall |
| 78 |
if ($child->has_child_nodes) { |
## into this category? |
| 79 |
$r .= '<ol class="children">'; |
|
| 80 |
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
## NOTE: This type has different model from normal XML types. |
| 81 |
} |
'application/rdf+xml' => 'WebHACC::Language::XML', |
| 82 |
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
}->{$input->{media_type}} || 'WebHACC::Language::Default'; |
| 83 |
$r .= qq'<li id="$node_id" class="tree-doctype"><code><!DOCTYPE></code><ul class="attributes">'; |
|
| 84 |
$r .= qq[<li class="tree-doctype-name">Name = <q>@{[htescape ($child->name)]}</q></li>]; |
eval qq{ require $checker_class } or die "$0: Loading $checker_class: $@"; |
| 85 |
$r .= qq[<li class="tree-doctype-publicid">Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>]; |
my $checker = $checker_class->new; |
| 86 |
$r .= qq[<li class="tree-doctype-systemid">System identifier = <q>@{[htescape ($child->system_id)]}</q></li>]; |
$checker->input ($input); |
| 87 |
$r .= '</ul></li>'; |
$checker->output ($out); |
| 88 |
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
$checker->result ($result); |
| 89 |
$r .= qq'<li id="$node_id" class="tree-id"><code><?@{[htescape ($child->target)]}</code> <q>@{[htescape ($child->data)]}</q><code>?></code></li>'; |
|
| 90 |
} else { |
## TODO: A cache manifest MUST be text/cache-manifest |
| 91 |
$r .= qq'<li id="$node_id" class="tree-unknown">@{[$child->node_type]} @{[htescape ($child->node_name)]}</li>'; # error |
## TODO: WebIDL media type "text/x-webidl" |
| 92 |
} |
|
| 93 |
|
$checker->generate_syntax_error_section; |
| 94 |
|
$checker->generate_source_string_section; |
| 95 |
|
|
| 96 |
|
my @subdoc; |
| 97 |
|
$checker->onsubdoc (sub { |
| 98 |
|
push @subdoc, shift; |
| 99 |
|
}); |
| 100 |
|
|
| 101 |
|
$checker->generate_structure_dump_section; |
| 102 |
|
$checker->generate_structure_error_section; |
| 103 |
|
$checker->generate_additional_sections; |
| 104 |
|
|
| 105 |
|
my $id_prefix = 0; |
| 106 |
|
for my $_subinput (@subdoc) { |
| 107 |
|
my $subinput = WebHACC::Input::Subdocument->new (++$id_prefix); |
| 108 |
|
$subinput->{$_} = $_subinput->{$_} for keys %$_subinput; |
| 109 |
|
$subinput->{base_uri} = $subinput->{container_node}->base_uri |
| 110 |
|
unless defined $subinput->{base_uri}; |
| 111 |
|
$subinput->{parent_input} = $input; |
| 112 |
|
|
| 113 |
|
$subinput->start_section ($result); |
| 114 |
|
check_and_print ($subinput => $result => $out); |
| 115 |
|
$subinput->end_section ($result); |
| 116 |
} |
} |
| 117 |
|
|
| 118 |
$r .= '</ol>'; |
$out->input ($original_input); |
| 119 |
print STDOUT $r; |
} # check_and_print |
|
} # print_document_tree |
|
|
|
|
|
sub get_node_path ($) { |
|
|
my $node = shift; |
|
|
my @r; |
|
|
while (defined $node) { |
|
|
my $rs; |
|
|
if ($node->node_type == 1) { |
|
|
$rs = $node->manakai_local_name; |
|
|
$node = $node->parent_node; |
|
|
} elsif ($node->node_type == 2) { |
|
|
$rs = '@' . $node->manakai_local_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 |
|
| 120 |
|
|
|
sub get_node_link ($) { |
|
|
return qq[<a href="#node-@{[refaddr $_[0]]}">] . |
|
|
htescape (get_node_path ($_[0])) . qq[</a>]; |
|
|
} # get_node_link |
|
| 121 |
|
|
| 122 |
{ |
{ |
| 123 |
my $Msg = {}; |
my $Msg = {}; |
| 124 |
|
|
| 125 |
sub load_text_catalog ($) { |
sub load_text_catalog ($) { |
| 126 |
|
# my $self = shift; |
| 127 |
my $lang = shift; # MUST be a canonical lang name |
my $lang = shift; # MUST be a canonical lang name |
| 128 |
open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!"; |
open my $file, '<:utf8', "cc-msg.$lang.txt" |
| 129 |
|
or die "$0: cc-msg.$lang.txt: $!"; |
| 130 |
while (<$file>) { |
while (<$file>) { |
| 131 |
if (s/^([^;]+);([^;]*);//) { |
if (s/^([^;]+);([^;]*);//) { |
| 132 |
my ($type, $cls, $msg) = ($1, $2, $_); |
my ($type, $cls, $msg) = ($1, $2, $_); |
| 136 |
} |
} |
| 137 |
} # load_text_catalog |
} # load_text_catalog |
| 138 |
|
|
| 139 |
sub get_text ($) { |
sub get_text ($;$$) { |
| 140 |
my ($type, $level) = @_; |
# my $self = shift; |
| 141 |
|
my ($type, $level, $node) = @_; |
| 142 |
$type = $level . ':' . $type if defined $level; |
$type = $level . ':' . $type if defined $level; |
| 143 |
|
$level = 'm' unless defined $level; |
| 144 |
my @arg; |
my @arg; |
| 145 |
{ |
{ |
| 146 |
if (defined $Msg->{$type}) { |
if (defined $Msg->{$type}) { |
| 147 |
my $msg = $Msg->{$type}->[1]; |
my $msg = $Msg->{$type}->[1]; |
| 148 |
$msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge; |
$msg =~ s{<var>\$([0-9]+)</var>}{ |
| 149 |
return ($Msg->{$type}->[0], $msg); |
defined $arg[$1] ? ($arg[$1]) : '(undef)'; |
| 150 |
|
}ge; ##BUG: ^ must be escaped |
| 151 |
|
$msg =~ s{<var>{\@([A-Za-z0-9:_.-]+)}</var>}{ |
| 152 |
|
UNIVERSAL::can ($node, 'get_attribute_ns') |
| 153 |
|
? ($node->get_attribute_ns (undef, $1)) : '' |
| 154 |
|
}ge; ## BUG: ^ must be escaped |
| 155 |
|
$msg =~ s{<var>{\@}</var>}{ ## BUG: v must be escaped |
| 156 |
|
UNIVERSAL::can ($node, 'value') ? ($node->value) : '' |
| 157 |
|
}ge; |
| 158 |
|
$msg =~ s{<var>{local-name}</var>}{ |
| 159 |
|
UNIVERSAL::can ($node, 'manakai_local_name') |
| 160 |
|
? ($node->manakai_local_name) : '' |
| 161 |
|
}ge; ## BUG: ^ must be escaped |
| 162 |
|
$msg =~ s{<var>{element-local-name}</var>}{ |
| 163 |
|
(UNIVERSAL::can ($node, 'owner_element') and |
| 164 |
|
$node->owner_element) |
| 165 |
|
? ($node->owner_element->manakai_local_name) |
| 166 |
|
: '' ## BUG: ^ must be escaped |
| 167 |
|
}ge; |
| 168 |
|
return ($type, 'level-' . $level . ' ' . $Msg->{$type}->[0], $msg); |
| 169 |
} elsif ($type =~ s/:([^:]*)$//) { |
} elsif ($type =~ s/:([^:]*)$//) { |
| 170 |
unshift @arg, $1; |
unshift @arg, $1; |
| 171 |
redo; |
redo; |
| 172 |
} |
} |
| 173 |
} |
} |
| 174 |
return ('', htescape ($_[0])); |
return ($type, 'level-'.$level, ($_[0])); |
| 175 |
|
## BUG: ^ must be escaped |
| 176 |
} # get_text |
} # get_text |
| 177 |
|
|
| 178 |
} |
} |
| 179 |
|
|
| 180 |
sub get_input_document ($$) { |
sub get_input_document ($) { |
| 181 |
my ($http, $dom) = @_; |
my $http = shift; |
| 182 |
|
|
| 183 |
my $request_uri = $http->parameter ('uri'); |
require Message::DOM::DOMImplementation; |
| 184 |
my $r = {}; |
my $dom = Message::DOM::DOMImplementation->new; |
| 185 |
|
|
| 186 |
|
require Encode; |
| 187 |
|
my $request_uri = Encode::decode ('utf-8', $http->get_parameter ('uri')); |
| 188 |
|
my $r = WebHACC::Input->new; |
| 189 |
if (defined $request_uri and length $request_uri) { |
if (defined $request_uri and length $request_uri) { |
| 190 |
my $uri = $dom->create_uri_reference ($request_uri); |
my $uri = $dom->create_uri_reference ($request_uri); |
| 191 |
unless ({ |
unless ({ |
| 192 |
http => 1, |
http => 1, |
| 193 |
}->{lc $uri->uri_scheme}) { |
}->{lc $uri->uri_scheme}) { |
| 194 |
return {uri => $request_uri, request_uri => $request_uri, |
$r = WebHACC::Input::Error->new; |
| 195 |
error_status_text => 'URI scheme not allowed'}; |
$r->{uri} = $request_uri; |
| 196 |
|
$r->{request_uri} = $request_uri; |
| 197 |
|
$r->{error_status_text} = 'URL scheme not allowed'; |
| 198 |
} |
} |
| 199 |
|
|
| 200 |
require Message::Util::HostPermit; |
require Message::Util::HostPermit; |
| 221 |
Allow host=* |
Allow host=* |
| 222 |
EOH |
EOH |
| 223 |
unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) { |
unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) { |
| 224 |
return {uri => $request_uri, request_uri => $request_uri, |
my $r = WebHACC::Input::Error->new; |
| 225 |
error_status_text => 'Connection to the host is forbidden'}; |
$r->{uri} = $request_uri; |
| 226 |
|
$r->{request_uri} = $request_uri; |
| 227 |
|
$r->{error_status_text} = 'Connection to the host is forbidden'; |
| 228 |
|
return $r; |
| 229 |
} |
} |
| 230 |
|
|
| 231 |
require LWP::UserAgent; |
require LWP::UserAgent; |
| 237 |
$ua->protocols_allowed ([qw/http/]); |
$ua->protocols_allowed ([qw/http/]); |
| 238 |
$ua->max_size (1000_000); |
$ua->max_size (1000_000); |
| 239 |
my $req = HTTP::Request->new (GET => $request_uri); |
my $req = HTTP::Request->new (GET => $request_uri); |
| 240 |
|
$req->header ('Accept-Encoding' => 'identity, *; q=0'); |
| 241 |
my $res = $ua->request ($req); |
my $res = $ua->request ($req); |
| 242 |
if ($res->is_success or $http->parameter ('error-page')) { |
## TODO: 401 sets |is_success| true. |
| 243 |
|
if ($res->is_success or $http->get_parameter ('error-page')) { |
| 244 |
$r->{base_uri} = $res->base; ## NOTE: It does check |Content-Base|, |Content-Location|, and <base>. ## TODO: Use our own code! |
$r->{base_uri} = $res->base; ## NOTE: It does check |Content-Base|, |Content-Location|, and <base>. ## TODO: Use our own code! |
| 245 |
$r->{uri} = $res->request->uri; |
$r->{uri} = $res->request->uri; |
| 246 |
$r->{request_uri} = $request_uri; |
$r->{request_uri} = $request_uri; |
| 247 |
|
|
| 248 |
## TODO: More strict parsing... |
## TODO: More strict parsing... |
| 249 |
my $ct = $res->header ('Content-Type'); |
my $ct = $res->header ('Content-Type'); |
| 250 |
if (defined $ct and $ct =~ m#^([0-9A-Za-z._+-]+/[0-9A-Za-z._+-]+)#) { |
if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) { |
|
$r->{media_type} = lc $1; |
|
|
} |
|
|
if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?(\S+)"?/i) { |
|
| 251 |
$r->{charset} = lc $1; |
$r->{charset} = lc $1; |
| 252 |
$r->{charset} =~ tr/\\//d; |
$r->{charset} =~ tr/\\//d; |
| 253 |
|
$r->{official_charset} = $r->{charset}; |
| 254 |
} |
} |
| 255 |
|
|
| 256 |
my $input_charset = $http->parameter ('charset'); |
my $input_charset = $http->get_parameter ('charset'); |
| 257 |
if (defined $input_charset and length $input_charset) { |
if (defined $input_charset and length $input_charset) { |
| 258 |
$r->{charset_overridden} |
$r->{charset_overridden} |
| 259 |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
| 260 |
$r->{charset} = $input_charset; |
$r->{charset} = $input_charset; |
| 261 |
} |
} |
| 262 |
|
|
| 263 |
|
## TODO: Support for HTTP Content-Encoding |
| 264 |
|
|
| 265 |
$r->{s} = ''.$res->content; |
$r->{s} = ''.$res->content; |
| 266 |
|
|
| 267 |
|
require Whatpm::ContentType; |
| 268 |
|
($r->{official_type}, $r->{media_type}) |
| 269 |
|
= Whatpm::ContentType->get_sniffed_type |
| 270 |
|
(get_file_head => sub { |
| 271 |
|
return substr $r->{s}, 0, shift; |
| 272 |
|
}, |
| 273 |
|
http_content_type_byte => $ct, |
| 274 |
|
has_http_content_encoding => |
| 275 |
|
defined $res->header ('Content-Encoding'), |
| 276 |
|
supported_image_types => {}); |
| 277 |
} else { |
} else { |
| 278 |
$r->{uri} = $res->request->uri; |
$r->{uri} = $res->request->uri; |
| 279 |
$r->{request_uri} = $request_uri; |
$r->{request_uri} = $request_uri; |
| 287 |
$r->{header_status_code} = $res->code; |
$r->{header_status_code} = $res->code; |
| 288 |
$r->{header_status_text} = $res->message; |
$r->{header_status_text} = $res->message; |
| 289 |
} else { |
} else { |
| 290 |
$r->{s} = ''.$http->parameter ('s'); |
$r->{s} = ''.$http->get_parameter ('s'); |
| 291 |
$r->{uri} = q<thismessage:/>; |
$r->{uri} = q<thismessage:/>; |
| 292 |
$r->{request_uri} = q<thismessage:/>; |
$r->{request_uri} = q<thismessage:/>; |
| 293 |
$r->{base_uri} = q<thismessage:/>; |
$r->{base_uri} = q<thismessage:/>; |
| 294 |
$r->{charset} = ''.$http->parameter ('_charset_'); |
$r->{charset} = ''.$http->get_parameter ('_charset_'); |
| 295 |
$r->{charset} =~ s/\s+//g; |
$r->{charset} =~ s/\s+//g; |
| 296 |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
| 297 |
|
$r->{official_charset} = $r->{charset}; |
| 298 |
$r->{header_field} = []; |
$r->{header_field} = []; |
| 299 |
|
|
| 300 |
|
require Whatpm::ContentType; |
| 301 |
|
($r->{official_type}, $r->{media_type}) |
| 302 |
|
= Whatpm::ContentType->get_sniffed_type |
| 303 |
|
(get_file_head => sub { |
| 304 |
|
return substr $r->{s}, 0, shift; |
| 305 |
|
}, |
| 306 |
|
http_content_type_byte => undef, |
| 307 |
|
has_http_content_encoding => 0, |
| 308 |
|
supported_image_types => {}); |
| 309 |
} |
} |
| 310 |
|
|
| 311 |
my $input_format = $http->parameter ('i'); |
my $input_format = $http->get_parameter ('i'); |
| 312 |
if (defined $input_format and length $input_format) { |
if (defined $input_format and length $input_format) { |
| 313 |
$r->{media_type_overridden} |
$r->{media_type_overridden} |
| 314 |
= (not defined $r->{media_type} or $input_format ne $r->{media_type}); |
= (not defined $r->{media_type} or $input_format ne $r->{media_type}); |
| 322 |
if ($r->{media_type} eq 'text/xml') { |
if ($r->{media_type} eq 'text/xml') { |
| 323 |
unless (defined $r->{charset}) { |
unless (defined $r->{charset}) { |
| 324 |
$r->{charset} = 'us-ascii'; |
$r->{charset} = 'us-ascii'; |
| 325 |
|
$r->{official_charset} = $r->{charset}; |
| 326 |
} elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') { |
} elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') { |
| 327 |
$r->{charset_overridden} = 0; |
$r->{charset_overridden} = 0; |
| 328 |
} |
} |
| 334 |
return $r; |
return $r; |
| 335 |
} |
} |
| 336 |
|
|
| 337 |
|
$r->{inner_html_element} = $http->get_parameter ('e'); |
| 338 |
|
|
| 339 |
return $r; |
return $r; |
| 340 |
} # get_input_document |
} # get_input_document |
| 341 |
|
|
| 368 |
|
|
| 369 |
=head1 LICENSE |
=head1 LICENSE |
| 370 |
|
|
| 371 |
Copyright 2007 Wakaba <w@suika.fam.cx> |
Copyright 2007-2008 Wakaba <w@suika.fam.cx> |
| 372 |
|
|
| 373 |
This library is free software; you can redistribute it |
This library is free software; you can redistribute it |
| 374 |
and/or modify it under the same terms as Perl itself. |
and/or modify it under the same terms as Perl itself. |