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]; |
7 |
use Scalar::Util qw[refaddr]; |
use Scalar::Util qw[refaddr]; |
8 |
|
use Time::HiRes qw/time/; |
|
use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module |
|
9 |
|
|
10 |
sub htescape ($) { |
sub htescape ($) { |
11 |
my $s = $_[0]; |
my $s = $_[0]; |
19 |
return $s; |
return $s; |
20 |
} # htescape |
} # htescape |
21 |
|
|
22 |
my $http = SuikaWiki::Input::HTTP->new; |
use Message::CGI::HTTP; |
23 |
|
my $http = Message::CGI::HTTP->new; |
|
## TODO: _charset_ |
|
24 |
|
|
25 |
if ($http->meta_variable ('PATH_INFO') ne '/') { |
if ($http->get_meta_variable ('PATH_INFO') ne '/') { |
26 |
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; |
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; |
27 |
exit; |
exit; |
28 |
} |
} |
51 |
|
|
52 |
$| = 0; |
$| = 0; |
53 |
my $input = get_input_document ($http, $dom); |
my $input = get_input_document ($http, $dom); |
54 |
my $inner_html_element = $http->parameter ('e'); |
my $inner_html_element = $http->get_parameter ('e'); |
55 |
|
my $char_length = 0; |
56 |
|
my %time; |
57 |
|
my $time1; |
58 |
|
my $time2; |
59 |
|
|
60 |
print qq[ |
print qq[ |
61 |
<div id="document-info" class="section"> |
<div id="document-info" class="section"> |
68 |
push @nav, ['#document-info' => 'Information']; |
push @nav, ['#document-info' => 'Information']; |
69 |
|
|
70 |
if (defined $input->{s}) { |
if (defined $input->{s}) { |
71 |
|
$char_length = length $input->{s}; |
72 |
|
|
73 |
print STDOUT qq[ |
print STDOUT qq[ |
74 |
<dt>Base URI</dt> |
<dt>Base URI</dt> |
79 |
<dt>Character Encoding</dt> |
<dt>Character Encoding</dt> |
80 |
<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)']} |
81 |
@{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
@{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd> |
82 |
|
<dt>Length</dt> |
83 |
|
<dd>$char_length byte@{[$char_length == 1 ? '' : 's']}</dd> |
84 |
</dl> |
</dl> |
85 |
</div> |
</div> |
86 |
]; |
]; |
95 |
require Whatpm::HTML; |
require Whatpm::HTML; |
96 |
|
|
97 |
$input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. |
$input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. |
98 |
|
|
99 |
|
$time1 = time; |
100 |
my $t = Encode::decode ($input->{charset}, $input->{s}); |
my $t = Encode::decode ($input->{charset}, $input->{s}); |
101 |
|
$time2 = time; |
102 |
|
$time{decode} = $time2 - $time1; |
103 |
|
|
104 |
print STDOUT qq[ |
print STDOUT qq[ |
105 |
<div id="parse-errors" class="section"> |
<div id="parse-errors" class="section"> |
124 |
}; |
}; |
125 |
|
|
126 |
$doc = $dom->create_document; |
$doc = $dom->create_document; |
127 |
|
$time1 = time; |
128 |
if (defined $inner_html_element and length $inner_html_element) { |
if (defined $inner_html_element and length $inner_html_element) { |
129 |
$el = $doc->create_element_ns |
$el = $doc->create_element_ns |
130 |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
132 |
} else { |
} else { |
133 |
Whatpm::HTML->parse_string ($t => $doc, $onerror); |
Whatpm::HTML->parse_string ($t => $doc, $onerror); |
134 |
} |
} |
135 |
|
$time2 = time; |
136 |
|
$time{parse} = $time2 - $time1; |
137 |
|
|
138 |
print STDOUT qq[</dl> |
print STDOUT qq[</dl> |
139 |
</div> |
</div> |
142 |
print_source_string_section (\($input->{s}), $input->{charset}); |
print_source_string_section (\($input->{s}), $input->{charset}); |
143 |
} elsif ({ |
} elsif ({ |
144 |
'text/xml' => 1, |
'text/xml' => 1, |
145 |
|
'application/atom+xml' => 1, |
146 |
|
'application/rss+xml' => 1, |
147 |
|
'application/svg+xml' => 1, |
148 |
'application/xhtml+xml' => 1, |
'application/xhtml+xml' => 1, |
149 |
'application/xml' => 1, |
'application/xml' => 1, |
150 |
}->{$input->{media_type}}) { |
}->{$input->{media_type}}) { |
166 |
return 1; |
return 1; |
167 |
}; |
}; |
168 |
|
|
169 |
|
$time1 = time; |
170 |
open my $fh, '<', \($input->{s}); |
open my $fh, '<', \($input->{s}); |
171 |
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
172 |
($fh => $dom, $onerror, charset => $input->{charset}); |
($fh => $dom, $onerror, charset => $input->{charset}); |
173 |
|
$time2 = time; |
174 |
|
$time{parse_xml} = $time2 - $time1; |
175 |
|
|
176 |
print STDOUT qq[</dl> |
print STDOUT qq[</dl> |
177 |
</div> |
</div> |
218 |
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
219 |
}; |
}; |
220 |
|
|
221 |
|
$time1 = time; |
222 |
my $elements; |
my $elements; |
223 |
if ($el) { |
if ($el) { |
224 |
$elements = Whatpm::ContentChecker->check_element ($el, $onerror); |
$elements = Whatpm::ContentChecker->check_element ($el, $onerror); |
225 |
} else { |
} else { |
226 |
$elements = Whatpm::ContentChecker->check_document ($doc, $onerror); |
$elements = Whatpm::ContentChecker->check_document ($doc, $onerror); |
227 |
} |
} |
228 |
|
$time2 = time; |
229 |
|
$time{check} = $time2 - $time1; |
230 |
|
|
231 |
print STDOUT qq[</dl> |
print STDOUT qq[</dl> |
232 |
</div> |
</div> |
367 |
</html> |
</html> |
368 |
]; |
]; |
369 |
|
|
370 |
|
for (qw/decode parse parse_xml check/) { |
371 |
|
next unless defined $time{$_}; |
372 |
|
open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; |
373 |
|
print $file $char_length, "\t", $time{$_}, "\n"; |
374 |
|
} |
375 |
|
|
376 |
exit; |
exit; |
377 |
|
|
378 |
sub print_http_header_section ($) { |
sub print_http_header_section ($) { |
575 |
$msg =~ s{<var>{\@}</var>}{ |
$msg =~ s{<var>{\@}</var>}{ |
576 |
UNIVERSAL::can ($node, 'value') ? htescape ($node->value) : '' |
UNIVERSAL::can ($node, 'value') ? htescape ($node->value) : '' |
577 |
}ge; |
}ge; |
578 |
|
$msg =~ s{<var>{local-name}</var>}{ |
579 |
|
UNIVERSAL::can ($node, 'manakai_local_name') |
580 |
|
? htescape ($node->manakai_local_name) : '' |
581 |
|
}ge; |
582 |
|
$msg =~ s{<var>{element-local-name}</var>}{ |
583 |
|
(UNIVERSAL::can ($node, 'owner_element') and |
584 |
|
$node->owner_element) |
585 |
|
? htescape ($node->owner_element->manakai_local_name) |
586 |
|
: '' |
587 |
|
}ge; |
588 |
return ($type, $Msg->{$type}->[0], $msg); |
return ($type, $Msg->{$type}->[0], $msg); |
589 |
} elsif ($type =~ s/:([^:]*)$//) { |
} elsif ($type =~ s/:([^:]*)$//) { |
590 |
unshift @arg, $1; |
unshift @arg, $1; |
599 |
sub get_input_document ($$) { |
sub get_input_document ($$) { |
600 |
my ($http, $dom) = @_; |
my ($http, $dom) = @_; |
601 |
|
|
602 |
my $request_uri = $http->parameter ('uri'); |
my $request_uri = $http->get_parameter ('uri'); |
603 |
my $r = {}; |
my $r = {}; |
604 |
if (defined $request_uri and length $request_uri) { |
if (defined $request_uri and length $request_uri) { |
605 |
my $uri = $dom->create_uri_reference ($request_uri); |
my $uri = $dom->create_uri_reference ($request_uri); |
648 |
$ua->max_size (1000_000); |
$ua->max_size (1000_000); |
649 |
my $req = HTTP::Request->new (GET => $request_uri); |
my $req = HTTP::Request->new (GET => $request_uri); |
650 |
my $res = $ua->request ($req); |
my $res = $ua->request ($req); |
651 |
if ($res->is_success or $http->parameter ('error-page')) { |
## TODO: 401 sets |is_success| true. |
652 |
|
if ($res->is_success or $http->get_parameter ('error-page')) { |
653 |
$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! |
654 |
$r->{uri} = $res->request->uri; |
$r->{uri} = $res->request->uri; |
655 |
$r->{request_uri} = $request_uri; |
$r->{request_uri} = $request_uri; |
664 |
$r->{charset} =~ tr/\\//d; |
$r->{charset} =~ tr/\\//d; |
665 |
} |
} |
666 |
|
|
667 |
my $input_charset = $http->parameter ('charset'); |
my $input_charset = $http->get_parameter ('charset'); |
668 |
if (defined $input_charset and length $input_charset) { |
if (defined $input_charset and length $input_charset) { |
669 |
$r->{charset_overridden} |
$r->{charset_overridden} |
670 |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
= (not defined $r->{charset} or $r->{charset} ne $input_charset); |
685 |
$r->{header_status_code} = $res->code; |
$r->{header_status_code} = $res->code; |
686 |
$r->{header_status_text} = $res->message; |
$r->{header_status_text} = $res->message; |
687 |
} else { |
} else { |
688 |
$r->{s} = ''.$http->parameter ('s'); |
$r->{s} = ''.$http->get_parameter ('s'); |
689 |
$r->{uri} = q<thismessage:/>; |
$r->{uri} = q<thismessage:/>; |
690 |
$r->{request_uri} = q<thismessage:/>; |
$r->{request_uri} = q<thismessage:/>; |
691 |
$r->{base_uri} = q<thismessage:/>; |
$r->{base_uri} = q<thismessage:/>; |
692 |
$r->{charset} = ''.$http->parameter ('_charset_'); |
$r->{charset} = ''.$http->get_parameter ('_charset_'); |
693 |
$r->{charset} =~ s/\s+//g; |
$r->{charset} =~ s/\s+//g; |
694 |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
$r->{charset} = 'utf-8' if $r->{charset} eq ''; |
695 |
$r->{header_field} = []; |
$r->{header_field} = []; |
696 |
} |
} |
697 |
|
|
698 |
my $input_format = $http->parameter ('i'); |
my $input_format = $http->get_parameter ('i'); |
699 |
if (defined $input_format and length $input_format) { |
if (defined $input_format and length $input_format) { |
700 |
$r->{media_type_overridden} |
$r->{media_type_overridden} |
701 |
= (not defined $r->{media_type} or $input_format ne $r->{media_type}); |
= (not defined $r->{media_type} or $input_format ne $r->{media_type}); |