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; |
13 |
$s =~ s/</</g; |
|
14 |
$s =~ s/>/>/g; |
require WebHACC::Output; |
15 |
$s =~ s/"/"/g; |
my $out = WebHACC::Output->new; |
16 |
$s =~ s!([\x00-\x09\x0B-\x1F\x7F-\x80])!sprintf '<var>U+%04X</var>', ord $1!ge; |
$out->handle (*STDOUT); |
17 |
return $s; |
$out->set_utf8; |
18 |
} # htescape |
|
19 |
|
if ($http->get_meta_variable ('PATH_INFO') ne '/') { |
20 |
my $http = SuikaWiki::Input::HTTP->new; |
$out->http_error (404); |
|
|
|
|
## TODO: _charset_ |
|
|
|
|
|
my $input_format = $http->parameter ('i') || 'text/html'; |
|
|
my $inner_html_element = $http->parameter ('e'); |
|
|
my $input_uri = 'thismessage:/'; |
|
|
|
|
|
my $s = $http->parameter ('s'); |
|
|
if (length $s > 1000_000) { |
|
|
print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long"; |
|
21 |
exit; |
exit; |
22 |
} |
} |
23 |
|
|
24 |
|
load_text_catalog ('en'); ## TODO: conneg |
25 |
|
|
26 |
print STDOUT qq[Content-Type: text/html; charset=utf-8 |
$out->set_flush; |
27 |
|
$out->http_header; |
28 |
|
$out->html_header; |
29 |
|
$out->unset_flush; |
30 |
|
|
31 |
<!DOCTYPE html> |
my $input = get_input_document ($http); |
32 |
<html lang="en"> |
$out->input ($input); |
|
<head> |
|
|
<title>Web Document Conformance Checker (BETA)</title> |
|
|
<link rel="stylesheet" href="/www/style/html/xhtml"> |
|
|
<style> |
|
|
q { |
|
|
white-space: pre; |
|
|
white-space: -moz-pre-wrap; |
|
|
white-space: pre-wrap; |
|
|
} |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
|
|
|
|
|
<dl> |
|
|
<dt>Document URI</dt> |
|
|
<dd><code class="URI" lang=""><<a href="@{[htescape $input_uri]}">@{[htescape $input_uri]}</a>></code></dd> |
|
|
<dt>Internet Media Type</dt> |
|
|
<dd><code class="MIME" lang="en">@{[htescape $input_format]}</code></dd> |
|
|
]; # no </dl> yet |
|
33 |
|
|
34 |
require Message::DOM::DOMImplementation; |
require WebHACC::Result; |
35 |
my $dom = Message::DOM::DOMImplementation->____new; |
my $result = WebHACC::Result->new; |
36 |
my $doc; |
$result->output ($out); |
37 |
my $el; |
$result->{conforming_min} = 1; |
38 |
|
$result->{conforming_max} = 1; |
|
if ($input_format eq 'text/html') { |
|
|
require Encode; |
|
|
require Whatpm::HTML; |
|
|
|
|
|
$s = Encode::decode ('utf-8', $s); |
|
|
|
|
|
print STDOUT qq[ |
|
|
<dt>Character Encoding</dt> |
|
|
<dd>(none)</dd> |
|
|
</dl> |
|
|
|
|
|
<div id="source-string" class="section"> |
|
|
]; |
|
|
print_source_string (\$s); |
|
|
print STDOUT qq[ |
|
|
</div> |
|
|
|
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Parse Errors</h2> |
|
|
|
|
|
<ul> |
|
|
]; |
|
|
|
|
|
my $onerror = sub { |
|
|
my (%opt) = @_; |
|
|
if ($opt{column} > 0) { |
|
|
print STDOUT qq[<li><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}: ]; |
|
|
} else { |
|
|
$opt{line}--; |
|
|
print STDOUT qq[<li><a href="#line-$opt{line}">Line $opt{line}</a>: ]; |
|
|
} |
|
|
print STDOUT qq[@{[htescape $opt{type}]}</li>\n]; |
|
|
}; |
|
39 |
|
|
40 |
$doc = $dom->create_document; |
$out->html ('<script src="../cc-script.js"></script>'); |
|
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, $s, $onerror); |
|
|
} else { |
|
|
Whatpm::HTML->parse_string ($s => $doc, $onerror); |
|
|
} |
|
41 |
|
|
42 |
print STDOUT qq[ |
check_and_print ($input => $result => $out); |
43 |
</ul> |
|
44 |
</div> |
$result->generate_result_section; |
45 |
]; |
|
46 |
} elsif ($input_format eq 'application/xhtml+xml') { |
$out->nav_list; |
47 |
require Message::DOM::XMLParserTemp; |
|
48 |
require Encode; |
exit; |
49 |
|
} |
50 |
my $t = Encode::decode ('utf-8', $s); |
|
51 |
|
sub check_and_print ($$$) { |
52 |
print STDOUT qq[ |
my ($input, $result, $out) = @_; |
53 |
<dt>Character Encoding</dt> |
my $original_input = $out->input; |
54 |
<dd>(none)</dd> |
$out->input ($input); |
55 |
</dl> |
|
56 |
|
$input->generate_info_section ($result); |
|
<div id="source-string" class="section"> |
|
|
]; |
|
|
print_source_string (\$t); |
|
|
print STDOUT qq[ |
|
|
</div> |
|
|
|
|
|
<div id="parse-errors" class="section"> |
|
|
<h2>Parse Errors</h2> |
|
|
|
|
|
<ul> |
|
|
]; |
|
|
|
|
|
my $onerror = sub { |
|
|
my $err = shift; |
|
|
my $line = $err->location->line_number; |
|
|
print STDOUT qq[<li><a href="#line-$line">Line $line</a> column ]; |
|
|
print STDOUT $err->location->column_number, ": "; |
|
|
print STDOUT htescape $err->text, "</li>\n"; |
|
|
return 1; |
|
|
}; |
|
|
|
|
|
open my $fh, '<', \$s; |
|
|
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
|
|
($fh => $dom, $onerror, charset => 'utf-8'); |
|
|
|
|
|
print STDOUT qq[ |
|
|
</ul> |
|
|
</div> |
|
|
]; |
|
|
} else { |
|
|
print STDOUT qq[ |
|
|
</dl> |
|
57 |
|
|
58 |
<p><em>Media type <code class="MIME" lang="en">@{[htescape $input_format]}</code> is not supported!</em></p> |
$input->generate_transfer_sections ($result); |
59 |
]; |
|
60 |
|
unless (defined $input->{s}) { |
61 |
|
$result->{conforming_min} = 0; |
62 |
|
return; |
63 |
|
} |
64 |
|
|
65 |
|
my $checker_class = { |
66 |
|
'text/cache-manifest' => 'WebHACC::Language::CacheManifest', |
67 |
|
'text/css' => 'WebHACC::Language::CSS', |
68 |
|
'text/html' => 'WebHACC::Language::HTML', |
69 |
|
'text/x-webidl' => 'WebHACC::Language::WebIDL', |
70 |
|
|
71 |
|
'text/xml' => 'WebHACC::Language::XML', |
72 |
|
'application/atom+xml' => 'WebHACC::Language::XML', |
73 |
|
'application/rss+xml' => 'WebHACC::Language::XML', |
74 |
|
'image/svg+xml' => 'WebHACC::Language::XML', |
75 |
|
'application/xhtml+xml' => 'WebHACC::Language::XML', |
76 |
|
'application/xml' => 'WebHACC::Language::XML', |
77 |
|
## TODO: Should we make all XML MIME Types fall |
78 |
|
## into this category? |
79 |
|
|
80 |
|
## NOTE: This type has different model from normal XML types. |
81 |
|
'application/rdf+xml' => 'WebHACC::Language::XML', |
82 |
|
}->{$input->{media_type}} || 'WebHACC::Language::Default'; |
83 |
|
|
84 |
|
eval qq{ require $checker_class } or die "$0: Loading $checker_class: $@"; |
85 |
|
my $checker = $checker_class->new; |
86 |
|
$checker->input ($input); |
87 |
|
$checker->output ($out); |
88 |
|
$checker->result ($result); |
89 |
|
|
90 |
|
## TODO: A cache manifest MUST be text/cache-manifest |
91 |
|
## 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 |
|
$out->input ($original_input); |
119 |
|
} # check_and_print |
120 |
|
|
|
if (defined $doc or defined $el) { |
|
|
print STDOUT qq[ |
|
|
<div id="document-tree" class="section"> |
|
|
<h2>Document Tree</h2> |
|
|
]; |
|
121 |
|
|
122 |
print_document_tree ($el || $doc); |
{ |
123 |
|
my $Msg = {}; |
124 |
|
|
125 |
|
sub load_text_catalog ($) { |
126 |
|
# my $self = shift; |
127 |
|
my $lang = shift; # MUST be a canonical lang name |
128 |
|
open my $file, '<:utf8', "cc-msg.$lang.txt" |
129 |
|
or die "$0: cc-msg.$lang.txt: $!"; |
130 |
|
while (<$file>) { |
131 |
|
if (s/^([^;]+);([^;]*);//) { |
132 |
|
my ($type, $cls, $msg) = ($1, $2, $_); |
133 |
|
$msg =~ tr/\x0D\x0A//d; |
134 |
|
$Msg->{$type} = [$cls, $msg]; |
135 |
|
} |
136 |
|
} |
137 |
|
} # load_text_catalog |
138 |
|
|
139 |
print STDOUT qq[ |
sub get_text ($;$$) { |
140 |
</div> |
# my $self = shift; |
141 |
|
my ($type, $level, $node) = @_; |
142 |
|
$type = $level . ':' . $type if defined $level; |
143 |
|
$level = 'm' unless defined $level; |
144 |
|
my @arg; |
145 |
|
{ |
146 |
|
if (defined $Msg->{$type}) { |
147 |
|
my $msg = $Msg->{$type}->[1]; |
148 |
|
$msg =~ s{<var>\$([0-9]+)</var>}{ |
149 |
|
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/:([^:]*)$//) { |
170 |
|
unshift @arg, $1; |
171 |
|
redo; |
172 |
|
} |
173 |
|
} |
174 |
|
return ($type, 'level-'.$level, ($_[0])); |
175 |
|
## BUG: ^ must be escaped |
176 |
|
} # get_text |
177 |
|
|
178 |
<div id="document-errors" class="section"> |
} |
|
<h2>Document Errors</h2> |
|
179 |
|
|
180 |
<ul> |
sub get_input_document ($) { |
181 |
]; |
my $http = shift; |
182 |
|
|
183 |
require Whatpm::ContentChecker; |
require Message::DOM::DOMImplementation; |
184 |
my $onerror = sub { |
my $dom = Message::DOM::DOMImplementation->new; |
|
my %opt = @_; |
|
|
print STDOUT qq[<li><a href="#node-@{[refaddr $opt{node}]}">], |
|
|
htescape get_node_path ($opt{node}), |
|
|
"</a>: ", htescape $opt{type}, "</li>\n"; |
|
|
}; |
|
185 |
|
|
186 |
if ($el) { |
require Encode; |
187 |
Whatpm::ContentChecker->check_element ($el, $onerror); |
my $request_uri = Encode::decode ('utf-8', $http->get_parameter ('uri')); |
188 |
} else { |
my $r = WebHACC::Input->new; |
189 |
Whatpm::ContentChecker->check_document ($doc, $onerror); |
if (defined $request_uri and length $request_uri) { |
190 |
|
my $uri = $dom->create_uri_reference ($request_uri); |
191 |
|
unless ({ |
192 |
|
http => 1, |
193 |
|
}->{lc $uri->uri_scheme}) { |
194 |
|
$r = WebHACC::Input::Error->new; |
195 |
|
$r->{uri} = $request_uri; |
196 |
|
$r->{request_uri} = $request_uri; |
197 |
|
$r->{error_status_text} = 'URL scheme not allowed'; |
198 |
} |
} |
199 |
|
|
200 |
print STDOUT qq[ |
require Message::Util::HostPermit; |
201 |
</ul> |
my $host_permit = new Message::Util::HostPermit; |
202 |
</div> |
$host_permit->add_rule (<<EOH); |
203 |
]; |
Allow host=suika port=80 |
204 |
} |
Deny host=suika |
205 |
|
Allow host=suika.fam.cx port=80 |
206 |
## TODO: Show result |
Deny host=suika.fam.cx |
207 |
print STDOUT qq[ |
Deny host=localhost |
208 |
</body> |
Deny host=*.localdomain |
209 |
</html> |
Deny ipv4=0.0.0.0/8 |
210 |
]; |
Deny ipv4=10.0.0.0/8 |
211 |
|
Deny ipv4=127.0.0.0/8 |
212 |
exit; |
Deny ipv4=169.254.0.0/16 |
213 |
|
Deny ipv4=172.0.0.0/11 |
214 |
sub print_source_string ($) { |
Deny ipv4=192.0.2.0/24 |
215 |
my $s = $_[0]; |
Deny ipv4=192.88.99.0/24 |
216 |
my $i = 1; |
Deny ipv4=192.168.0.0/16 |
217 |
print STDOUT qq[<ol lang="">\n]; |
Deny ipv4=198.18.0.0/15 |
218 |
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
Deny ipv4=224.0.0.0/4 |
219 |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
Deny ipv4=255.255.255.255/32 |
220 |
$i++; |
Deny ipv6=0::0/0 |
221 |
} |
Allow host=* |
222 |
if ($$s =~ /\G([^\x0A]+)/gc) { |
EOH |
223 |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) { |
224 |
} |
my $r = WebHACC::Input::Error->new; |
225 |
print STDOUT "</ol>"; |
$r->{uri} = $request_uri; |
226 |
} # print_input_string |
$r->{request_uri} = $request_uri; |
227 |
|
$r->{error_status_text} = 'Connection to the host is forbidden'; |
228 |
sub print_document_tree ($) { |
return $r; |
|
my $node = shift; |
|
|
my $r = '<ol class="xoxo">'; |
|
|
|
|
|
my @node = ($node); |
|
|
while (@node) { |
|
|
my $child = shift @node; |
|
|
unless (ref $child) { |
|
|
$r .= $child; |
|
|
next; |
|
229 |
} |
} |
230 |
|
|
231 |
my $node_id = 'node-'.refaddr $child; |
require LWP::UserAgent; |
232 |
my $nt = $child->node_type; |
my $ua = WDCC::LWPUA->new; |
233 |
if ($nt == $child->ELEMENT_NODE) { |
$ua->{wdcc_dom} = $dom; |
234 |
$r .= qq'<li id="$node_id"><code>' . htescape ($child->tag_name) . |
$ua->{wdcc_host_permit} = $host_permit; |
235 |
'</code>'; ## ISSUE: case |
$ua->agent ('Mozilla'); ## TODO: for now. |
236 |
|
$ua->parse_head (0); |
237 |
if ($child->has_attributes) { |
$ua->protocols_allowed ([qw/http/]); |
238 |
$r .= '<ul class="attributes">'; |
$ua->max_size (1000_000); |
239 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, 'node-'.refaddr $_] } |
my $req = HTTP::Request->new (GET => $request_uri); |
240 |
@{$child->attributes}) { |
$req->header ('Accept-Encoding' => 'identity, *; q=0'); |
241 |
$r .= qq'<li id="$attr->[2]"><code>' . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
my $res = $ua->request ($req); |
242 |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
## TODO: 401 sets |is_success| true. |
243 |
} |
if ($res->is_success or $http->get_parameter ('error-page')) { |
244 |
$r .= '</ul>'; |
$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; |
246 |
|
$r->{request_uri} = $request_uri; |
247 |
|
|
248 |
|
## TODO: More strict parsing... |
249 |
|
my $ct = $res->header ('Content-Type'); |
250 |
|
if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) { |
251 |
|
$r->{charset} = lc $1; |
252 |
|
$r->{charset} =~ tr/\\//d; |
253 |
|
$r->{official_charset} = $r->{charset}; |
254 |
} |
} |
255 |
|
|
256 |
if ($node->has_child_nodes) { |
my $input_charset = $http->get_parameter ('charset'); |
257 |
$r .= '<ol class="children">'; |
if (defined $input_charset and length $input_charset) { |
258 |
unshift @node, @{$child->child_nodes}, '</ol>'; |
$r->{charset_overridden} |
259 |
|
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
260 |
|
$r->{charset} = $input_charset; |
261 |
} |
} |
262 |
} elsif ($nt == $child->TEXT_NODE) { |
|
263 |
$r .= qq'<li id="$node_id"><q>' . htescape ($child->data) . '</q></li>'; |
## TODO: Support for HTTP Content-Encoding |
264 |
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
|
265 |
$r .= qq'<li id="$node_id"><code><[CDATA[</code><q>' . htescape ($child->data) . '</q><code>]]></code></li>'; |
$r->{s} = ''.$res->content; |
266 |
} elsif ($nt == $child->COMMENT_NODE) { |
|
267 |
$r .= qq'<li id="$node_id"><code><!--</code><q>' . htescape ($child->data) . '</q><code>--></code></li>'; |
require Whatpm::ContentType; |
268 |
} elsif ($nt == $child->DOCUMENT_NODE) { |
($r->{official_type}, $r->{media_type}) |
269 |
$r .= qq'<li id="$node_id">Document</li>'; |
= Whatpm::ContentType->get_sniffed_type |
270 |
if ($child->has_child_nodes) { |
(get_file_head => sub { |
271 |
$r .= '<ol>'; |
return substr $r->{s}, 0, shift; |
272 |
unshift @node, @{$child->child_nodes}, '</ol>'; |
}, |
273 |
} |
http_content_type_byte => $ct, |
274 |
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
has_http_content_encoding => |
275 |
$r .= qq'<li id="$node_id"><code><!DOCTYPE></code><ul>'; |
defined $res->header ('Content-Encoding'), |
276 |
$r .= '<li>Name = <q>@{[htescape ($child->name)]}</q></li>'; |
supported_image_types => {}); |
|
$r .= '<li>Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>'; |
|
|
$r .= '<li>System identifier = <q>@{[htescape ($child->system_id)]}</q></li>'; |
|
|
$r .= '</ul></li>'; |
|
|
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
|
|
$r .= qq'<li id="$node_id"><code><?@{[htescape ($child->target)]}?></code>'; |
|
|
$r .= '<ul><li>@{[htescape ($child->data)]}</li></ul></li>'; |
|
277 |
} else { |
} else { |
278 |
$r .= qq'<li id="$node_id">@{[$child->node_type]} @{[htescape ($child->node_name)]}</li>'; # error |
$r->{uri} = $res->request->uri; |
279 |
|
$r->{request_uri} = $request_uri; |
280 |
|
$r->{error_status_text} = $res->status_line; |
281 |
} |
} |
282 |
|
|
283 |
|
$r->{header_field} = []; |
284 |
|
$res->scan (sub { |
285 |
|
push @{$r->{header_field}}, [$_[0], $_[1]]; |
286 |
|
}); |
287 |
|
$r->{header_status_code} = $res->code; |
288 |
|
$r->{header_status_text} = $res->message; |
289 |
|
} else { |
290 |
|
$r->{s} = ''.$http->get_parameter ('s'); |
291 |
|
$r->{uri} = q<thismessage:/>; |
292 |
|
$r->{request_uri} = q<thismessage:/>; |
293 |
|
$r->{base_uri} = q<thismessage:/>; |
294 |
|
$r->{charset} = ''.$http->get_parameter ('_charset_'); |
295 |
|
$r->{charset} =~ s/\s+//g; |
296 |
|
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
297 |
|
$r->{official_charset} = $r->{charset}; |
298 |
|
$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 |
$r .= '</ol>'; |
my $input_format = $http->get_parameter ('i'); |
312 |
print STDOUT $r; |
if (defined $input_format and length $input_format) { |
313 |
} # print_document_tree |
$r->{media_type_overridden} |
314 |
|
= (not defined $r->{media_type} or $input_format ne $r->{media_type}); |
315 |
sub get_node_path ($) { |
$r->{media_type} = $input_format; |
316 |
my $node = shift; |
} |
317 |
my @r; |
if (defined $r->{s} and not defined $r->{media_type}) { |
318 |
while (defined $node) { |
$r->{media_type} = 'text/html'; |
319 |
my $rs; |
$r->{media_type_overridden} = 1; |
320 |
if ($node->node_type == 1) { |
} |
321 |
$rs = $node->manakai_local_name; |
|
322 |
$node = $node->parent_node; |
if ($r->{media_type} eq 'text/xml') { |
323 |
} elsif ($node->node_type == 2) { |
unless (defined $r->{charset}) { |
324 |
$rs = '@' . $node->manakai_local_name; |
$r->{charset} = 'us-ascii'; |
325 |
$node = $node->owner_element; |
$r->{official_charset} = $r->{charset}; |
326 |
} elsif ($node->node_type == 3) { |
} elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') { |
327 |
$rs = '"' . $node->data . '"'; |
$r->{charset_overridden} = 0; |
|
$node = $node->parent_node; |
|
|
} elsif ($node->node_type == 9) { |
|
|
$rs = ''; |
|
|
$node = $node->parent_node; |
|
|
} else { |
|
|
$rs = '#' . $node->node_type; |
|
|
$node = $node->parent_node; |
|
328 |
} |
} |
|
unshift @r, $rs; |
|
329 |
} |
} |
330 |
return join '/', @r; |
|
331 |
} # get_node_path |
if (length $r->{s} > 1000_000) { |
332 |
|
$r->{error_status_text} = 'Entity-body too large'; |
333 |
|
delete $r->{s}; |
334 |
|
return $r; |
335 |
|
} |
336 |
|
|
337 |
|
$r->{inner_html_element} = $http->get_parameter ('e'); |
338 |
|
|
339 |
|
return $r; |
340 |
|
} # get_input_document |
341 |
|
|
342 |
|
package WDCC::LWPUA; |
343 |
|
BEGIN { push our @ISA, 'LWP::UserAgent'; } |
344 |
|
|
345 |
|
sub redirect_ok { |
346 |
|
my $ua = shift; |
347 |
|
unless ($ua->SUPER::redirect_ok (@_)) { |
348 |
|
return 0; |
349 |
|
} |
350 |
|
|
351 |
|
my $uris = $_[1]->header ('Location'); |
352 |
|
return 0 unless $uris; |
353 |
|
my $uri = $ua->{wdcc_dom}->create_uri_reference ($uris); |
354 |
|
unless ({ |
355 |
|
http => 1, |
356 |
|
}->{lc $uri->uri_scheme}) { |
357 |
|
return 0; |
358 |
|
} |
359 |
|
unless ($ua->{wdcc_host_permit}->check ($uri->uri_host, $uri->uri_port || 80)) { |
360 |
|
return 0; |
361 |
|
} |
362 |
|
return 1; |
363 |
|
} # redirect_ok |
364 |
|
|
365 |
=head1 AUTHOR |
=head1 AUTHOR |
366 |
|
|
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. |