1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
|
4 |
|
|
use lib qw[/home/httpd/html/www/markup/html/whatpm |
5 |
wakaba |
1.16 |
/home/wakaba/work/manakai2/lib]; |
6 |
wakaba |
1.1 |
use CGI::Carp qw[fatalsToBrowser]; |
7 |
|
|
|
8 |
wakaba |
1.53 |
require WebHACC::Input; |
9 |
wakaba |
1.2 |
|
10 |
wakaba |
1.35 |
{ |
11 |
wakaba |
1.58 |
require Message::CGI::HTTP; |
12 |
wakaba |
1.16 |
my $http = Message::CGI::HTTP->new; |
13 |
wakaba |
1.1 |
|
14 |
wakaba |
1.58 |
require WebHACC::Output; |
15 |
|
|
my $out = WebHACC::Output->new; |
16 |
|
|
$out->handle (*STDOUT); |
17 |
|
|
$out->set_utf8; |
18 |
|
|
|
19 |
wakaba |
1.16 |
if ($http->get_meta_variable ('PATH_INFO') ne '/') { |
20 |
wakaba |
1.58 |
$out->http_error (404); |
21 |
wakaba |
1.8 |
exit; |
22 |
|
|
} |
23 |
wakaba |
1.59 |
|
24 |
|
|
## TODO: We need real conneg support... |
25 |
|
|
my $primary_language = 'en'; |
26 |
|
|
if ($ENV{HTTP_ACCEPT_LANGUAGE} =~ /ja/) { |
27 |
|
|
$primary_language = 'ja'; |
28 |
|
|
} |
29 |
|
|
$out->load_text_catalog ($primary_language); |
30 |
wakaba |
1.53 |
|
31 |
|
|
$out->set_flush; |
32 |
wakaba |
1.58 |
$out->http_header; |
33 |
|
|
$out->html_header; |
34 |
|
|
$out->unset_flush; |
35 |
wakaba |
1.55 |
|
36 |
wakaba |
1.61 |
$out->generate_input_section ($http); |
37 |
|
|
|
38 |
|
|
my $u = $http->get_parameter ('uri'); |
39 |
|
|
my $s = $http->get_parameter ('s'); |
40 |
|
|
if ((not defined $u or not length $u) and |
41 |
|
|
(not defined $s or not length $s)) { |
42 |
|
|
exit; |
43 |
|
|
} |
44 |
|
|
|
45 |
wakaba |
1.58 |
require WebHACC::Result; |
46 |
wakaba |
1.55 |
my $result = WebHACC::Result->new; |
47 |
wakaba |
1.60 |
$result->output ($out); |
48 |
wakaba |
1.14 |
|
49 |
wakaba |
1.60 |
require WebHACC::Input; |
50 |
|
|
my $input = WebHACC::Input->get_document ($http => $result => $out); |
51 |
wakaba |
1.54 |
|
52 |
wakaba |
1.55 |
check_and_print ($input => $result => $out); |
53 |
|
|
|
54 |
wakaba |
1.53 |
$out->nav_list; |
55 |
wakaba |
1.16 |
|
56 |
wakaba |
1.53 |
exit; |
57 |
wakaba |
1.35 |
} |
58 |
wakaba |
1.1 |
|
59 |
wakaba |
1.53 |
sub check_and_print ($$$) { |
60 |
|
|
my ($input, $result, $out) = @_; |
61 |
|
|
my $original_input = $out->input; |
62 |
|
|
$out->input ($input); |
63 |
wakaba |
1.31 |
|
64 |
wakaba |
1.55 |
$input->generate_info_section ($result); |
65 |
|
|
|
66 |
wakaba |
1.54 |
$input->generate_transfer_sections ($result); |
67 |
wakaba |
1.31 |
|
68 |
wakaba |
1.55 |
unless (defined $input->{s}) { |
69 |
wakaba |
1.62 |
## NOTE: This is an error of the implementation. |
70 |
|
|
$result->layer_uncertain ('transfer'); |
71 |
|
|
$result->generate_result_section; |
72 |
wakaba |
1.63 |
|
73 |
|
|
$out->input ($original_input); |
74 |
wakaba |
1.55 |
return; |
75 |
|
|
} |
76 |
wakaba |
1.31 |
|
77 |
wakaba |
1.53 |
my $checker_class = { |
78 |
|
|
'text/cache-manifest' => 'WebHACC::Language::CacheManifest', |
79 |
|
|
'text/css' => 'WebHACC::Language::CSS', |
80 |
|
|
'text/html' => 'WebHACC::Language::HTML', |
81 |
wakaba |
1.64 |
'text/x-h2h' => 'WebHACC::Language::H2H', |
82 |
wakaba |
1.53 |
'text/x-webidl' => 'WebHACC::Language::WebIDL', |
83 |
|
|
|
84 |
|
|
'text/xml' => 'WebHACC::Language::XML', |
85 |
|
|
'application/atom+xml' => 'WebHACC::Language::XML', |
86 |
|
|
'application/rss+xml' => 'WebHACC::Language::XML', |
87 |
|
|
'image/svg+xml' => 'WebHACC::Language::XML', |
88 |
|
|
'application/xhtml+xml' => 'WebHACC::Language::XML', |
89 |
|
|
'application/xml' => 'WebHACC::Language::XML', |
90 |
|
|
## TODO: Should we make all XML MIME Types fall |
91 |
|
|
## into this category? |
92 |
|
|
|
93 |
|
|
## NOTE: This type has different model from normal XML types. |
94 |
|
|
'application/rdf+xml' => 'WebHACC::Language::XML', |
95 |
|
|
}->{$input->{media_type}} || 'WebHACC::Language::Default'; |
96 |
|
|
|
97 |
|
|
eval qq{ require $checker_class } or die "$0: Loading $checker_class: $@"; |
98 |
|
|
my $checker = $checker_class->new; |
99 |
|
|
$checker->input ($input); |
100 |
|
|
$checker->output ($out); |
101 |
|
|
$checker->result ($result); |
102 |
|
|
|
103 |
|
|
## TODO: A cache manifest MUST be text/cache-manifest |
104 |
|
|
## TODO: WebIDL media type "text/x-webidl" |
105 |
|
|
|
106 |
|
|
$checker->generate_syntax_error_section; |
107 |
|
|
$checker->generate_source_string_section; |
108 |
|
|
|
109 |
wakaba |
1.55 |
my @subdoc; |
110 |
wakaba |
1.53 |
$checker->onsubdoc (sub { |
111 |
|
|
push @subdoc, shift; |
112 |
|
|
}); |
113 |
|
|
|
114 |
|
|
$checker->generate_structure_dump_section; |
115 |
|
|
$checker->generate_structure_error_section; |
116 |
|
|
$checker->generate_additional_sections; |
117 |
|
|
|
118 |
wakaba |
1.34 |
my $id_prefix = 0; |
119 |
wakaba |
1.53 |
for my $_subinput (@subdoc) { |
120 |
wakaba |
1.55 |
my $subinput = WebHACC::Input::Subdocument->new (++$id_prefix); |
121 |
wakaba |
1.53 |
$subinput->{$_} = $_subinput->{$_} for keys %$_subinput; |
122 |
wakaba |
1.34 |
$subinput->{base_uri} = $subinput->{container_node}->base_uri |
123 |
|
|
unless defined $subinput->{base_uri}; |
124 |
wakaba |
1.55 |
$subinput->{parent_input} = $input; |
125 |
wakaba |
1.34 |
|
126 |
wakaba |
1.62 |
my $subresult = WebHACC::Result->new; |
127 |
|
|
$subresult->output ($out); |
128 |
|
|
$subresult->parent_result ($result); |
129 |
|
|
|
130 |
|
|
$subinput->start_section ($subresult); |
131 |
|
|
check_and_print ($subinput => $subresult => $out); |
132 |
|
|
$subinput->end_section ($subresult); |
133 |
wakaba |
1.34 |
} |
134 |
wakaba |
1.53 |
|
135 |
wakaba |
1.62 |
$result->generate_result_section; |
136 |
|
|
|
137 |
wakaba |
1.53 |
$out->input ($original_input); |
138 |
wakaba |
1.31 |
} # check_and_print |
139 |
|
|
|
140 |
wakaba |
1.1 |
=head1 AUTHOR |
141 |
|
|
|
142 |
|
|
Wakaba <w@suika.fam.cx>. |
143 |
|
|
|
144 |
|
|
=head1 LICENSE |
145 |
|
|
|
146 |
wakaba |
1.35 |
Copyright 2007-2008 Wakaba <w@suika.fam.cx> |
147 |
wakaba |
1.1 |
|
148 |
|
|
This library is free software; you can redistribute it |
149 |
|
|
and/or modify it under the same terms as Perl itself. |
150 |
|
|
|
151 |
|
|
=cut |
152 |
|
|
|
153 |
wakaba |
1.64 |
## $Date: 2008/08/15 16:44:03 $ |