52 |
|
|
53 |
$| = 0; |
$| = 0; |
54 |
my $input = get_input_document ($http, $dom); |
my $input = get_input_document ($http, $dom); |
|
my $inner_html_element = $http->get_parameter ('e'); |
|
55 |
my $char_length = 0; |
my $char_length = 0; |
56 |
my %time; |
my %time; |
57 |
|
|
61 |
<dt>Request URI</dt> |
<dt>Request URI</dt> |
62 |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>></code></dd> |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>></code></dd> |
63 |
<dt>Document URI</dt> |
<dt>Document URI</dt> |
64 |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{uri}]}">@{[htescape $input->{uri}]}</a>></code></dd> |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{uri}]}" id=anchor-document-uri>@{[htescape $input->{uri}]}</a>></code> |
65 |
|
<script> |
66 |
|
document.title = '<' |
67 |
|
+ document.getElementById ('anchor-document-uri').href + '> \\u2014 ' |
68 |
|
+ document.title; |
69 |
|
</script></dd> |
70 |
]; # no </dl> yet |
]; # no </dl> yet |
71 |
push @nav, ['#document-info' => 'Information']; |
push @nav, ['#document-info' => 'Information']; |
72 |
|
|
78 |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>></code></dd> |
<dd><code class="URI" lang=""><<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>></code></dd> |
79 |
<dt>Internet Media Type</dt> |
<dt>Internet Media Type</dt> |
80 |
<dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> |
<dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> |
81 |
@{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
@{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : defined $input->{official_type} ? $input->{media_type} eq $input->{official_type} ? '' : '<em>(sniffed; official type is: <code class=MIME lang=en>'.htescape ($input->{official_type}).'</code>)' : '<em>(sniffed)</em>']}</dd> |
82 |
<dt>Character Encoding</dt> |
<dt>Character Encoding</dt> |
83 |
<dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']} |
<dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']} |
84 |
@{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
@{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
97 |
|
|
98 |
if ($input->{media_type} eq 'text/html') { |
if ($input->{media_type} eq 'text/html') { |
99 |
($doc, $el) = print_syntax_error_html_section ($input, $result); |
($doc, $el) = print_syntax_error_html_section ($input, $result); |
100 |
print_source_string_section (\($input->{s}), $input->{charset}); |
print_source_string_section |
101 |
|
(\($input->{s}), $input->{charset} || $doc->input_encoding); |
102 |
} elsif ({ |
} elsif ({ |
103 |
'text/xml' => 1, |
'text/xml' => 1, |
104 |
'application/atom+xml' => 1, |
'application/atom+xml' => 1, |
115 |
print_source_string_section (\($input->{s}), 'utf-8'); |
print_source_string_section (\($input->{s}), 'utf-8'); |
116 |
} else { |
} else { |
117 |
## TODO: Change HTTP status code?? |
## TODO: Change HTTP status code?? |
118 |
print_result_unknown_type_section ($input); |
print_result_unknown_type_section ($input, $result); |
119 |
} |
} |
120 |
|
|
121 |
if (defined $doc or defined $el) { |
if (defined $doc or defined $el) { |
148 |
</html> |
</html> |
149 |
]; |
]; |
150 |
|
|
151 |
for (qw/decode parse parse_xml parse_manifest check check_manifest/) { |
for (qw/decode parse parse_html parse_xml parse_manifest |
152 |
|
check check_manifest/) { |
153 |
next unless defined $time{$_}; |
next unless defined $time{$_}; |
154 |
open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; |
open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; |
155 |
print $file $char_length, "\t", $time{$_}, "\n"; |
print $file $char_length, "\t", $time{$_}, "\n"; |
224 |
|
|
225 |
require Encode; |
require Encode; |
226 |
require Whatpm::HTML; |
require Whatpm::HTML; |
|
|
|
|
$input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. |
|
227 |
|
|
|
my $time1 = time; |
|
|
my $t = Encode::decode ($input->{charset}, $input->{s}); |
|
|
$time{decode} = time - $time1; |
|
|
|
|
228 |
print STDOUT qq[ |
print STDOUT qq[ |
229 |
<div id="parse-errors" class="section"> |
<div id="parse-errors" class="section"> |
230 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
252 |
|
|
253 |
my $doc = $dom->create_document; |
my $doc = $dom->create_document; |
254 |
my $el; |
my $el; |
255 |
$time1 = time; |
my $inner_html_element = $http->get_parameter ('e'); |
256 |
if (defined $inner_html_element and length $inner_html_element) { |
if (defined $inner_html_element and length $inner_html_element) { |
257 |
|
$input->{charset} ||= 'windows-1252'; ## TODO: for now. |
258 |
|
my $time1 = time; |
259 |
|
my $t = Encode::decode ($input->{charset}, $input->{s}); |
260 |
|
$time{decode} = time - $time1; |
261 |
|
|
262 |
$el = $doc->create_element_ns |
$el = $doc->create_element_ns |
263 |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
264 |
|
$time1 = time; |
265 |
Whatpm::HTML->set_inner_html ($el, $t, $onerror); |
Whatpm::HTML->set_inner_html ($el, $t, $onerror); |
266 |
|
$time{parse} = time - $time1; |
267 |
} else { |
} else { |
268 |
Whatpm::HTML->parse_string ($t => $doc, $onerror); |
my $time1 = time; |
269 |
|
Whatpm::HTML->parse_byte_string |
270 |
|
($input->{charset}, $input->{s} => $doc, $onerror); |
271 |
|
$time{parse_html} = time - $time1; |
272 |
} |
} |
273 |
$time{parse} = time - $time1; |
$doc->manakai_charset ($input->{official_charset}) |
274 |
|
if defined $input->{official_charset}; |
275 |
|
|
276 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
277 |
|
|
278 |
return ($doc, $el); |
return ($doc, $el); |
312 |
my $doc = Message::DOM::XMLParserTemp->parse_byte_stream |
my $doc = Message::DOM::XMLParserTemp->parse_byte_stream |
313 |
($fh => $dom, $onerror, charset => $input->{charset}); |
($fh => $dom, $onerror, charset => $input->{charset}); |
314 |
$time{parse_xml} = time - $time1; |
$time{parse_xml} = time - $time1; |
315 |
|
$doc->manakai_charset ($input->{official_charset}) |
316 |
|
if defined $input->{official_charset}; |
317 |
|
|
318 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
319 |
|
|
403 |
$r .= '<ul class="attributes">'; |
$r .= '<ul class="attributes">'; |
404 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
405 |
@{$child->attributes}) { |
@{$child->attributes}) { |
406 |
$r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $_->[2] ? $_->[2] : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
$r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $attr->[2] ? htescape ($attr->[2]) : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
407 |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
408 |
} |
} |
409 |
$r .= '</ul>'; |
$r .= '</ul>'; |
424 |
} elsif ($nt == $child->DOCUMENT_NODE) { |
} elsif ($nt == $child->DOCUMENT_NODE) { |
425 |
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
426 |
$r .= qq[<ul class="attributes">]; |
$r .= qq[<ul class="attributes">]; |
427 |
|
my $cp = $child->manakai_charset; |
428 |
|
if (defined $cp) { |
429 |
|
$r .= qq[<li><code>charset</code> parameter = <code>]; |
430 |
|
$r .= htescape ($cp) . qq[</code></li>]; |
431 |
|
} |
432 |
|
$r .= qq[<li><code>inputEncoding</code> = ]; |
433 |
|
my $ie = $child->input_encoding; |
434 |
|
if (defined $ie) { |
435 |
|
$r .= qq[<code>@{[htescape ($ie)]}</code>]; |
436 |
|
if ($child->manakai_has_bom) { |
437 |
|
$r .= qq[ (with <code class=charname><abbr>BOM</abbr></code>)]; |
438 |
|
} |
439 |
|
} else { |
440 |
|
$r .= qq[(<code>null</code>)]; |
441 |
|
} |
442 |
$r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>]; |
$r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>]; |
443 |
$r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>]; |
$r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>]; |
444 |
unless ($child->manakai_is_html) { |
unless ($child->manakai_is_html) { |
787 |
push @nav, ['#result-summary' => 'Result']; |
push @nav, ['#result-summary' => 'Result']; |
788 |
} # print_result_section |
} # print_result_section |
789 |
|
|
790 |
sub print_result_unknown_type_section ($) { |
sub print_result_unknown_type_section ($$) { |
791 |
my $input = shift; |
my ($input, $result) = @_; |
792 |
|
|
793 |
|
my $euri = htescape ($input->{uri}); |
794 |
print STDOUT qq[ |
print STDOUT qq[ |
795 |
<div id="result-summary" class="section"> |
<div id="parse-errors" class="section"> |
796 |
<p><em>Media type <code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> is not supported!</em></p> |
<h2>Errors</h2> |
797 |
|
|
798 |
|
<dl> |
799 |
|
<dt class=unsupported><code><<a href="$euri">$euri</a>></code></dt> |
800 |
|
<dd class=unsupported><strong><a href="../error-description#level-u">Not |
801 |
|
supported</a></strong>: |
802 |
|
Media type |
803 |
|
<code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> |
804 |
|
is not supported.</dd> |
805 |
|
</dl> |
806 |
</div> |
</div> |
807 |
]; |
]; |
808 |
push @nav, ['#result-summary' => 'Result']; |
push @nav, ['#parse-errors' => 'Errors']; |
809 |
|
add_error (char => {level => 'unsupported'} => $result); |
810 |
|
add_error (syntax => {level => 'unsupported'} => $result); |
811 |
|
add_error (structure => {level => 'unsupported'} => $result); |
812 |
} # print_result_unknown_type_section |
} # print_result_unknown_type_section |
813 |
|
|
814 |
sub print_result_input_error_section ($) { |
sub print_result_input_error_section ($) { |
914 |
|
|
915 |
sub load_text_catalog ($) { |
sub load_text_catalog ($) { |
916 |
my $lang = shift; # MUST be a canonical lang name |
my $lang = shift; # MUST be a canonical lang name |
917 |
open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!"; |
open my $file, '<:utf8', "cc-msg.$lang.txt" |
918 |
|
or die "$0: cc-msg.$lang.txt: $!"; |
919 |
while (<$file>) { |
while (<$file>) { |
920 |
if (s/^([^;]+);([^;]*);//) { |
if (s/^([^;]+);([^;]*);//) { |
921 |
my ($type, $cls, $msg) = ($1, $2, $_); |
my ($type, $cls, $msg) = ($1, $2, $_); |
928 |
sub get_text ($) { |
sub get_text ($) { |
929 |
my ($type, $level, $node) = @_; |
my ($type, $level, $node) = @_; |
930 |
$type = $level . ':' . $type if defined $level; |
$type = $level . ':' . $type if defined $level; |
931 |
|
$level = 'm' unless defined $level; |
932 |
my @arg; |
my @arg; |
933 |
{ |
{ |
934 |
if (defined $Msg->{$type}) { |
if (defined $Msg->{$type}) { |
953 |
? htescape ($node->owner_element->manakai_local_name) |
? htescape ($node->owner_element->manakai_local_name) |
954 |
: '' |
: '' |
955 |
}ge; |
}ge; |
956 |
return ($type, $Msg->{$type}->[0], $msg); |
return ($type, 'level-' . $level . ' ' . $Msg->{$type}->[0], $msg); |
957 |
} elsif ($type =~ s/:([^:]*)$//) { |
} elsif ($type =~ s/:([^:]*)$//) { |
958 |
unshift @arg, $1; |
unshift @arg, $1; |
959 |
redo; |
redo; |
960 |
} |
} |
961 |
} |
} |
962 |
return ($type, '', htescape ($_[0])); |
return ($type, 'level-'.$level, htescape ($_[0])); |
963 |
} # get_text |
} # get_text |
964 |
|
|
965 |
} |
} |
1015 |
$ua->protocols_allowed ([qw/http/]); |
$ua->protocols_allowed ([qw/http/]); |
1016 |
$ua->max_size (1000_000); |
$ua->max_size (1000_000); |
1017 |
my $req = HTTP::Request->new (GET => $request_uri); |
my $req = HTTP::Request->new (GET => $request_uri); |
1018 |
|
$req->header ('Accept-Encoding' => 'identity, *; q=0'); |
1019 |
my $res = $ua->request ($req); |
my $res = $ua->request ($req); |
1020 |
## TODO: 401 sets |is_success| true. |
## TODO: 401 sets |is_success| true. |
1021 |
if ($res->is_success or $http->get_parameter ('error-page')) { |
if ($res->is_success or $http->get_parameter ('error-page')) { |
1025 |
|
|
1026 |
## TODO: More strict parsing... |
## TODO: More strict parsing... |
1027 |
my $ct = $res->header ('Content-Type'); |
my $ct = $res->header ('Content-Type'); |
|
if (defined $ct and $ct =~ m#^([0-9A-Za-z._+-]+/[0-9A-Za-z._+-]+)#) { |
|
|
$r->{media_type} = lc $1; |
|
|
} |
|
1028 |
if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) { |
if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) { |
1029 |
$r->{charset} = lc $1; |
$r->{charset} = lc $1; |
1030 |
$r->{charset} =~ tr/\\//d; |
$r->{charset} =~ tr/\\//d; |
1031 |
|
$r->{official_charset} = $r->{charset}; |
1032 |
} |
} |
1033 |
|
|
1034 |
my $input_charset = $http->get_parameter ('charset'); |
my $input_charset = $http->get_parameter ('charset'); |
1036 |
$r->{charset_overridden} |
$r->{charset_overridden} |
1037 |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
1038 |
$r->{charset} = $input_charset; |
$r->{charset} = $input_charset; |
1039 |
} |
} |
1040 |
|
|
1041 |
|
## TODO: Support for HTTP Content-Encoding |
1042 |
|
|
1043 |
$r->{s} = ''.$res->content; |
$r->{s} = ''.$res->content; |
1044 |
|
|
1045 |
|
require Whatpm::ContentType; |
1046 |
|
($r->{official_type}, $r->{media_type}) |
1047 |
|
= Whatpm::ContentType->get_sniffed_type |
1048 |
|
(get_file_head => sub { |
1049 |
|
return substr $r->{s}, 0, shift; |
1050 |
|
}, |
1051 |
|
http_content_type_byte => $ct, |
1052 |
|
has_http_content_encoding => |
1053 |
|
defined $res->header ('Content-Encoding'), |
1054 |
|
supported_image_types => {}); |
1055 |
} else { |
} else { |
1056 |
$r->{uri} = $res->request->uri; |
$r->{uri} = $res->request->uri; |
1057 |
$r->{request_uri} = $request_uri; |
$r->{request_uri} = $request_uri; |
1072 |
$r->{charset} = ''.$http->get_parameter ('_charset_'); |
$r->{charset} = ''.$http->get_parameter ('_charset_'); |
1073 |
$r->{charset} =~ s/\s+//g; |
$r->{charset} =~ s/\s+//g; |
1074 |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
1075 |
|
$r->{official_charset} = $r->{charset}; |
1076 |
$r->{header_field} = []; |
$r->{header_field} = []; |
1077 |
|
|
1078 |
|
require Whatpm::ContentType; |
1079 |
|
($r->{official_type}, $r->{media_type}) |
1080 |
|
= Whatpm::ContentType->get_sniffed_type |
1081 |
|
(get_file_head => sub { |
1082 |
|
return substr $r->{s}, 0, shift; |
1083 |
|
}, |
1084 |
|
http_content_type_byte => undef, |
1085 |
|
has_http_content_encoding => 0, |
1086 |
|
supported_image_types => {}); |
1087 |
} |
} |
1088 |
|
|
1089 |
my $input_format = $http->get_parameter ('i'); |
my $input_format = $http->get_parameter ('i'); |
1100 |
if ($r->{media_type} eq 'text/xml') { |
if ($r->{media_type} eq 'text/xml') { |
1101 |
unless (defined $r->{charset}) { |
unless (defined $r->{charset}) { |
1102 |
$r->{charset} = 'us-ascii'; |
$r->{charset} = 'us-ascii'; |
1103 |
|
$r->{official_charset} = $r->{charset}; |
1104 |
} elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') { |
} elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') { |
1105 |
$r->{charset_overridden} = 0; |
$r->{charset_overridden} = 0; |
1106 |
} |
} |