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, |
252 |
|
|
253 |
my $doc = $dom->create_document; |
my $doc = $dom->create_document; |
254 |
my $el; |
my $el; |
255 |
|
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} ||= 'ISO-8859-1'; ## TODO: for now. |
$input->{charset} ||= 'windows-1252'; ## TODO: for now. |
258 |
my $time1 = time; |
my $time1 = time; |
259 |
my $t = Encode::decode ($input->{charset}, $input->{s}); |
my $t = Encode::decode ($input->{charset}, $input->{s}); |
260 |
$time{decode} = time - $time1; |
$time{decode} = time - $time1; |
270 |
($input->{charset}, $input->{s} => $doc, $onerror); |
($input->{charset}, $input->{s} => $doc, $onerror); |
271 |
$time{parse_html} = time - $time1; |
$time{parse_html} = time - $time1; |
272 |
} |
} |
273 |
|
$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 |
|
|
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) { |
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, $_); |
1014 |
$ua->protocols_allowed ([qw/http/]); |
$ua->protocols_allowed ([qw/http/]); |
1015 |
$ua->max_size (1000_000); |
$ua->max_size (1000_000); |
1016 |
my $req = HTTP::Request->new (GET => $request_uri); |
my $req = HTTP::Request->new (GET => $request_uri); |
1017 |
|
$req->header ('Accept-Encoding' => 'identity, *; q=0'); |
1018 |
my $res = $ua->request ($req); |
my $res = $ua->request ($req); |
1019 |
## TODO: 401 sets |is_success| true. |
## TODO: 401 sets |is_success| true. |
1020 |
if ($res->is_success or $http->get_parameter ('error-page')) { |
if ($res->is_success or $http->get_parameter ('error-page')) { |
1024 |
|
|
1025 |
## TODO: More strict parsing... |
## TODO: More strict parsing... |
1026 |
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; |
|
|
} |
|
1027 |
if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) { |
if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) { |
1028 |
$r->{charset} = lc $1; |
$r->{charset} = lc $1; |
1029 |
$r->{charset} =~ tr/\\//d; |
$r->{charset} =~ tr/\\//d; |
1030 |
|
$r->{official_charset} = $r->{charset}; |
1031 |
} |
} |
1032 |
|
|
1033 |
my $input_charset = $http->get_parameter ('charset'); |
my $input_charset = $http->get_parameter ('charset'); |
1035 |
$r->{charset_overridden} |
$r->{charset_overridden} |
1036 |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
1037 |
$r->{charset} = $input_charset; |
$r->{charset} = $input_charset; |
1038 |
} |
} |
1039 |
|
|
1040 |
|
## TODO: Support for HTTP Content-Encoding |
1041 |
|
|
1042 |
$r->{s} = ''.$res->content; |
$r->{s} = ''.$res->content; |
1043 |
|
|
1044 |
|
require Whatpm::ContentType; |
1045 |
|
($r->{official_type}, $r->{media_type}) |
1046 |
|
= Whatpm::ContentType->get_sniffed_type |
1047 |
|
(get_file_head => sub { |
1048 |
|
return substr $r->{s}, 0, shift; |
1049 |
|
}, |
1050 |
|
http_content_type_byte => $ct, |
1051 |
|
has_http_content_encoding => |
1052 |
|
defined $res->header ('Content-Encoding'), |
1053 |
|
supported_image_types => {}); |
1054 |
} else { |
} else { |
1055 |
$r->{uri} = $res->request->uri; |
$r->{uri} = $res->request->uri; |
1056 |
$r->{request_uri} = $request_uri; |
$r->{request_uri} = $request_uri; |
1071 |
$r->{charset} = ''.$http->get_parameter ('_charset_'); |
$r->{charset} = ''.$http->get_parameter ('_charset_'); |
1072 |
$r->{charset} =~ s/\s+//g; |
$r->{charset} =~ s/\s+//g; |
1073 |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
1074 |
|
$r->{official_charset} = $r->{charset}; |
1075 |
$r->{header_field} = []; |
$r->{header_field} = []; |
1076 |
|
|
1077 |
|
require Whatpm::ContentType; |
1078 |
|
($r->{official_type}, $r->{media_type}) |
1079 |
|
= Whatpm::ContentType->get_sniffed_type |
1080 |
|
(get_file_head => sub { |
1081 |
|
return substr $r->{s}, 0, shift; |
1082 |
|
}, |
1083 |
|
http_content_type_byte => undef, |
1084 |
|
has_http_content_encoding => 0, |
1085 |
|
supported_image_types => {}); |
1086 |
} |
} |
1087 |
|
|
1088 |
my $input_format = $http->get_parameter ('i'); |
my $input_format = $http->get_parameter ('i'); |
1099 |
if ($r->{media_type} eq 'text/xml') { |
if ($r->{media_type} eq 'text/xml') { |
1100 |
unless (defined $r->{charset}) { |
unless (defined $r->{charset}) { |
1101 |
$r->{charset} = 'us-ascii'; |
$r->{charset} = 'us-ascii'; |
1102 |
|
$r->{official_charset} = $r->{charset}; |
1103 |
} elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') { |
} elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') { |
1104 |
$r->{charset_overridden} = 0; |
$r->{charset_overridden} = 0; |
1105 |
} |
} |