/[pub]/test/html-webhacc/cc.cgi
Suika

Diff of /test/html-webhacc/cc.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by wakaba, Sun Jul 1 10:02:24 2007 UTC revision 1.59 by wakaba, Mon Jul 21 12:56:33 2008 UTC
# Line 2  Line 2 
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;
   $s =~ s/</&lt;/g;  
   $s =~ s/>/&gt;/g;  
   $s =~ s/"/&quot;/g;  
   $s =~ s!([\x00-\x09\x0B-\x1F\x7F-\x80])!sprintf '<var>U+%04X</var>', ord $1!ge;  
   return $s;  
 } # htescape  
   
 my $http = SuikaWiki::Input::HTTP->new;  
   
 ## TODO: _charset_  
13    
14    if ($http->meta_variable ('PATH_INFO') ne '/') {    require WebHACC::Output;
15      print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400";    my $out = WebHACC::Output->new;
16      exit;    $out->handle (*STDOUT);
17    }    $out->set_utf8;
18    
19    my $input_format = $http->parameter ('i') || 'text/html';    if ($http->get_meta_variable ('PATH_INFO') ne '/') {
20    my $inner_html_element = $http->parameter ('e');      $out->http_error (404);
   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    ## 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      
31      $out->set_flush;
32      $out->http_header;
33      $out->html_header;
34      $out->unset_flush;
35    
36      my $input = get_input_document ($http);
37      $out->input ($input);
38    
39      require WebHACC::Result;
40      my $result = WebHACC::Result->new;
41      $result->output ($out);
42      $result->{conforming_min} = 1;
43      $result->{conforming_max} = 1;
44    
45      $out->html ('<script src="../cc-script.js"></script>');
46    
47      check_and_print ($input => $result => $out);
48      
49      $result->generate_result_section;
50    
51    my @nav;    $out->nav_list;
   print STDOUT qq[Content-Type: text/html; charset=utf-8  
52    
53  <!DOCTYPE html>    exit;
54  <html lang="en">  }
 <head>  
 <title>Web Document Conformance Checker (BETA)</title>  
 <link rel="stylesheet" href="../cc-style.css" type="text/css">  
 </head>  
 <body>  
 <h1>Web Document Conformance Checker (<em>beta</em>)</h1>  
   
 <div id="document-info" class="section">  
 <dl>  
 <dt>Document URI</dt>  
     <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input_uri]}">@{[htescape $input_uri]}</a>&gt;</code></dd>  
 <dt>Internet Media Type</dt>  
     <dd><code class="MIME" lang="en">@{[htescape $input_format]}</code></dd>  
 ]; # no </dl> yet  
   push @nav, ['#document-info' => 'Information'];  
55    
56    require Message::DOM::DOMImplementation;  sub check_and_print ($$$) {
57    my $dom = Message::DOM::DOMImplementation->____new;    my ($input, $result, $out) = @_;
58    my $doc;    my $original_input = $out->input;
59    my $el;    $out->input ($input);
60    
61    if ($input_format eq 'text/html') {    $input->generate_info_section ($result);
62      require Encode;  
63      require Whatpm::HTML;    $input->generate_transfer_sections ($result);
64        
65      $s = Encode::decode ('utf-8', $s);    unless (defined $input->{s}) {
66        $result->{conforming_min} = 0;
67      print STDOUT qq[      return;
68  <dt>Character Encoding</dt>    }
69      <dd>(none)</dd>  
70  </dl>    my $checker_class = {
71  </div>      'text/cache-manifest' => 'WebHACC::Language::CacheManifest',
72        'text/css' => 'WebHACC::Language::CSS',
73  <div id="source-string" class="section">      'text/html' => 'WebHACC::Language::HTML',
74  <h2>Document Source</h2>      'text/x-webidl' => 'WebHACC::Language::WebIDL',
75  ];  
76      push @nav, ['#source-string' => 'Source'];      'text/xml' => 'WebHACC::Language::XML',
77      print_source_string (\$s);      'application/atom+xml' => 'WebHACC::Language::XML',
78      print STDOUT qq[      'application/rss+xml' => 'WebHACC::Language::XML',
79  </div>      'image/svg+xml' => 'WebHACC::Language::XML',
80        'application/xhtml+xml' => 'WebHACC::Language::XML',
81  <div id="parse-errors" class="section">      'application/xml' => 'WebHACC::Language::XML',
82  <h2>Parse Errors</h2>      ## TODO: Should we make all XML MIME Types fall
83        ## into this category?
84  <dl>  
85  ];      ## NOTE: This type has different model from normal XML types.
86    push @nav, ['#parse-errors' => 'Parse Error'];      'application/rdf+xml' => 'WebHACC::Language::XML',
87      }->{$input->{media_type}} || 'WebHACC::Language::Default';
88    my $onerror = sub {  
89      my (%opt) = @_;    eval qq{ require $checker_class } or die "$0: Loading $checker_class: $@";
90      my ($cls, $msg) = get_text ($opt{type}, $opt{level});    my $checker = $checker_class->new;
91      if ($opt{column} > 0) {    $checker->input ($input);
92        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n];    $checker->output ($out);
93      } else {    $checker->result ($result);
94        $opt{line} = $opt{line} - 1 || 1;  
95        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n];    ## TODO: A cache manifest MUST be text/cache-manifest
96      }    ## TODO: WebIDL media type "text/x-webidl"
97      $opt{type} =~ tr/ /-/;  
98      $opt{type} =~ s/\|/%7C/g;    $checker->generate_syntax_error_section;
99      $msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]];    $checker->generate_source_string_section;
100      print STDOUT qq[<dd class="$cls">$msg</dd>\n];  
101    };    my @subdoc;
102      $checker->onsubdoc (sub {
103    $doc = $dom->create_document;      push @subdoc, shift;
104    if (defined $inner_html_element and length $inner_html_element) {    });
105      $el = $doc->create_element_ns  
106          ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]);    $checker->generate_structure_dump_section;
107      Whatpm::HTML->set_inner_html ($el, $s, $onerror);    $checker->generate_structure_error_section;
108    } else {    $checker->generate_additional_sections;
109      Whatpm::HTML->parse_string ($s => $doc, $onerror);  
110      my $id_prefix = 0;
111      for my $_subinput (@subdoc) {
112        my $subinput = WebHACC::Input::Subdocument->new (++$id_prefix);
113        $subinput->{$_} = $_subinput->{$_} for keys %$_subinput;
114        $subinput->{base_uri} = $subinput->{container_node}->base_uri
115            unless defined $subinput->{base_uri};
116        $subinput->{parent_input} = $input;
117    
118        $subinput->start_section ($result);
119        check_and_print ($subinput => $result => $out);
120        $subinput->end_section ($result);
121    }    }
122    
123    print STDOUT qq[    $out->input ($original_input);
124  </dl>  } # check_and_print
 </div>  
 ];  
   } elsif ($input_format eq 'application/xhtml+xml') {  
     require Message::DOM::XMLParserTemp;  
     require Encode;  
       
     my $t = Encode::decode ('utf-8', $s);  
   
     print STDOUT qq[  
 <dt>Character Encoding</dt>  
     <dd>(none)</dd>  
 </dl>  
 </div>  
   
 <div id="source-string" class="section">  
 <h2>Document Source</h2>  
 ];  
     push @nav, ['#source-string' => 'Source'];  
     print_source_string (\$t);  
     print STDOUT qq[  
 </div>  
   
 <div id="parse-errors" class="section">  
 <h2>Parse Errors</h2>  
   
 <dl>];  
   push @nav, ['#parse-errors' => 'Parse Error'];  
   
   my $onerror = sub {  
     my $err = shift;  
     my $line = $err->location->line_number;  
     print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ];  
     print STDOUT $err->location->column_number, "</dt><dd>";  
     print STDOUT htescape $err->text, "</dd>\n";  
     return 1;  
   };  
   
   open my $fh, '<', \$s;  
   $doc = Message::DOM::XMLParserTemp->parse_byte_stream  
       ($fh => $dom, $onerror, charset => 'utf-8');  
   
     print STDOUT qq[</dl>  
 </div>  
 ];  
   } else {  
     print STDOUT qq[  
 </dl>  
 </div>  
   
 <div id="result-summary" class="section">  
 <p><em>Media type <code class="MIME" lang="en">@{[htescape $input_format]}</code> is not supported!</em></p>  
 </div>  
 ];  
     push @nav, ['#result-summary' => 'Result'];  
   }  
125    
126    sub get_input_document ($) {
127      my $http = shift;
128    
129    if (defined $doc or defined $el) {    require Message::DOM::DOMImplementation;
130      print STDOUT qq[    my $dom = Message::DOM::DOMImplementation->new;
 <div id="document-tree" class="section">  
 <h2>Document Tree</h2>  
 ];  
     push @nav, ['#document-tree' => 'Tree'];  
   
     print_document_tree ($el || $doc);  
   
     print STDOUT qq[  
 </div>  
   
 <div id="document-errors" class="section">  
 <h2>Document Errors</h2>  
   
 <dl>];  
     push @nav, ['#document-errors' => 'Document Error'];  
   
     require Whatpm::ContentChecker;  
     my $onerror = sub {  
       my %opt = @_;  
       my ($cls, $msg) = get_text ($opt{type}, $opt{level});  
       $opt{type} = $opt{level} . ':' . $opt{type} if defined $opt{level};  
       $opt{type} =~ tr/ /-/;  
       $opt{type} =~ s/\|/%7C/g;  
       $msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]];  
       print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) .  
           qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n";  
     };  
   
     my $elements;  
     if ($el) {  
       $elements = Whatpm::ContentChecker->check_element ($el, $onerror);  
     } else {  
       $elements = Whatpm::ContentChecker->check_document ($doc, $onerror);  
     }  
131    
132      print STDOUT qq[</dl>    require Encode;
133  </div>    my $request_uri = Encode::decode ('utf-8', $http->get_parameter ('uri'));
134  ];    my $r = WebHACC::Input->new;
135      if (defined $request_uri and length $request_uri) {
136      if (@{$elements->{table}}) {      my $uri = $dom->create_uri_reference ($request_uri);
137        require JSON;      unless ({
138                 http => 1,
139        print STDOUT qq[              }->{lc $uri->uri_scheme}) {
140  <div id="tables" class="section">        $r = WebHACC::Input::Error->new;
141  <h2>Tables</h2>        $r->{uri} = $request_uri;
142          $r->{request_uri} = $request_uri;
143  <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->        $r->{error_status_text} = 'URL scheme not allowed';
144  <script src="../table-script.js" type="text/javascript"></script>      }
145  <noscript>  
146  <p><em>Structure of tables are visualized here if scripting is enabled.</em></p>      require Message::Util::HostPermit;
147  </noscript>      my $host_permit = new Message::Util::HostPermit;
148  ];      $host_permit->add_rule (<<EOH);
149    Allow host=suika port=80
150        my $i = 0;  Deny host=suika
151        for my $table_el (@{$elements->{table}}) {  Allow host=suika.fam.cx port=80
152          $i++;  Deny host=suika.fam.cx
153          print STDOUT qq[<div class="section" id="table-$i"><h3>] .  Deny host=localhost
154              get_node_link ($table_el) . q[</h3>];  Deny host=*.localdomain
155            Deny ipv4=0.0.0.0/8
156          my $table = Whatpm::HTMLTable->form_table ($table_el);  Deny ipv4=10.0.0.0/8
157            Deny ipv4=127.0.0.0/8
158          for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) {  Deny ipv4=169.254.0.0/16
159            next unless $_;  Deny ipv4=172.0.0.0/11
160            delete $_->{element};  Deny ipv4=192.0.2.0/24
161          }  Deny ipv4=192.88.99.0/24
162            Deny ipv4=192.168.0.0/16
163          for (@{$table->{row_group}}) {  Deny ipv4=198.18.0.0/15
164            next unless $_;  Deny ipv4=224.0.0.0/4
165            next unless $_->{element};  Deny ipv4=255.255.255.255/32
166            $_->{type} = $_->{element}->manakai_local_name;  Deny ipv6=0::0/0
167            delete $_->{element};  Allow host=*
168          }  EOH
169                unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) {
170          for (@{$table->{cell}}) {        my $r = WebHACC::Input::Error->new;
171            next unless $_;        $r->{uri} = $request_uri;
172            for (@{$_}) {        $r->{request_uri} = $request_uri;
173              next unless $_;        $r->{error_status_text} = 'Connection to the host is forbidden';
174              for (@$_) {        return $r;
175                $_->{id} = refaddr $_->{element} if defined $_->{element};      }
176                delete $_->{element};  
177              }      require LWP::UserAgent;
178            }      my $ua = WDCC::LWPUA->new;
179          }      $ua->{wdcc_dom} = $dom;
180                $ua->{wdcc_host_permit} = $host_permit;
181          print STDOUT '</div><script type="text/javascript">tableToCanvas (';      $ua->agent ('Mozilla'); ## TODO: for now.
182          print STDOUT JSON::objToJson ($table);      $ua->parse_head (0);
183          print STDOUT qq[, document.getElementById ('table-$i'));</script>];      $ua->protocols_allowed ([qw/http/]);
184        $ua->max_size (1000_000);
185        my $req = HTTP::Request->new (GET => $request_uri);
186        $req->header ('Accept-Encoding' => 'identity, *; q=0');
187        my $res = $ua->request ($req);
188        ## TODO: 401 sets |is_success| true.
189        if ($res->is_success or $http->get_parameter ('error-page')) {
190          $r->{base_uri} = $res->base; ## NOTE: It does check |Content-Base|, |Content-Location|, and <base>. ## TODO: Use our own code!
191          $r->{uri} = $res->request->uri;
192          $r->{request_uri} = $request_uri;
193    
194          ## TODO: More strict parsing...
195          my $ct = $res->header ('Content-Type');
196          if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?([^\s;"]+)"?/i) {
197            $r->{charset} = lc $1;
198            $r->{charset} =~ tr/\\//d;
199            $r->{official_charset} = $r->{charset};
200        }        }
       
       print STDOUT qq[</div>];  
     }  
201    
202      if (keys %{$elements->{term}}) {        my $input_charset = $http->get_parameter ('charset');
203        print STDOUT qq[        if (defined $input_charset and length $input_charset) {
204  <div id="terms" class="section">          $r->{charset_overridden}
205  <h2>Terms</h2>              = (not defined $r->{charset} or $r->{charset} ne $input_charset);
206            $r->{charset} = $input_charset;
 <dl>  
 ];  
       for my $term (sort {$a cmp $b} keys %{$elements->{term}}) {  
         print STDOUT qq[<dt>@{[htescape $term]}</dt>];  
         for (@{$elements->{term}->{$term}}) {  
           print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>];  
         }  
207        }        }
       print STDOUT qq[</dl></div>];  
     }  
   }  
   
   ## TODO: Show result  
   
   print STDOUT qq[  
 <ul class="navigation" id="nav-items">  
 ];  
   for (@nav) {  
     print STDOUT qq[<li><a href="$_->[0]">$_->[1]</a></li>];  
   }  
   print STDOUT qq[  
 </ul>  
 </body>  
 </html>  
 ];  
   
 exit;  
   
 sub print_source_string ($) {  
   my $s = $_[0];  
   my $i = 1;  
   print STDOUT qq[<ol lang="">\n];  
   if (length $$s) {  
     while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {  
       print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";  
       $i++;  
     }  
     if ($$s =~ /\G([^\x0A]+)/gc) {  
       print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";  
     }  
   } else {  
     print STDOUT q[<li id="line-1"></li>];  
   }  
   print STDOUT "</ol>";  
 } # print_input_string  
208    
209  sub print_document_tree ($) {        ## TODO: Support for HTTP Content-Encoding
   my $node = shift;  
   my $r = '<ol class="xoxo">';  
   
   my @node = ($node);  
   while (@node) {  
     my $child = shift @node;  
     unless (ref $child) {  
       $r .= $child;  
       next;  
     }  
210    
211      my $node_id = 'node-'.refaddr $child;        $r->{s} = ''.$res->content;
     my $nt = $child->node_type;  
     if ($nt == $child->ELEMENT_NODE) {  
       my $child_nsuri = $child->namespace_uri;  
       $r .= qq[<li id="$node_id" class="tree-element"><code title="@{[defined $child_nsuri ? $child_nsuri : '']}">] . htescape ($child->tag_name) .  
           '</code>'; ## ISSUE: case  
   
       if ($child->has_attributes) {  
         $r .= '<ul class="attributes">';  
         for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] }  
                       @{$child->attributes}) {  
           $r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $_->[2] ? $_->[2] : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case?  
           $r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children  
         }  
         $r .= '</ul>';  
       }  
212    
213        if ($child->has_child_nodes) {        require Whatpm::ContentType;
214          $r .= '<ol class="children">';        ($r->{official_type}, $r->{media_type})
215          unshift @node, @{$child->child_nodes}, '</ol></li>';            = Whatpm::ContentType->get_sniffed_type
216        } else {                (get_file_head => sub {
217          $r .= '</li>';                   return substr $r->{s}, 0, shift;
218        }                 },
219      } elsif ($nt == $child->TEXT_NODE) {                 http_content_type_byte => $ct,
220        $r .= qq'<li id="$node_id" class="tree-text"><q lang="">' . htescape ($child->data) . '</q></li>';                 has_http_content_encoding =>
221      } elsif ($nt == $child->CDATA_SECTION_NODE) {                     defined $res->header ('Content-Encoding'),
222        $r .= qq'<li id="$node_id" class="tree-cdata"><code>&lt;[CDATA[</code><q lang="">' . htescape ($child->data) . '</q><code>]]&gt;</code></li>';                 supported_image_types => {});
     } elsif ($nt == $child->COMMENT_NODE) {  
       $r .= qq'<li id="$node_id" class="tree-comment"><code>&lt;!--</code><q lang="">' . htescape ($child->data) . '</q><code>--&gt;</code></li>';  
     } elsif ($nt == $child->DOCUMENT_NODE) {  
       $r .= qq'<li id="$node_id" class="tree-document">Document';  
       $r .= qq[<ul class="attributes">];  
       $r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>];  
       $r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>];  
       $r .= qq[</ul>];  
       if ($child->has_child_nodes) {  
         $r .= '<ol class="children">';  
         unshift @node, @{$child->child_nodes}, '</ol></li>';  
       }  
     } elsif ($nt == $child->DOCUMENT_TYPE_NODE) {  
       $r .= qq'<li id="$node_id" class="tree-doctype"><code>&lt;!DOCTYPE&gt;</code><ul class="attributes">';  
       $r .= qq[<li class="tree-doctype-name">Name = <q>@{[htescape ($child->name)]}</q></li>];  
       $r .= qq[<li class="tree-doctype-publicid">Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>];  
       $r .= qq[<li class="tree-doctype-systemid">System identifier = <q>@{[htescape ($child->system_id)]}</q></li>];  
       $r .= '</ul></li>';  
     } elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) {  
       $r .= qq'<li id="$node_id" class="tree-id"><code>&lt;?@{[htescape ($child->target)]}</code> <q>@{[htescape ($child->data)]}</q><code>?&gt;</code></li>';  
223      } else {      } else {
224        $r .= qq'<li id="$node_id" class="tree-unknown">@{[$child->node_type]} @{[htescape ($child->node_name)]}</li>'; # error        $r->{uri} = $res->request->uri;
225          $r->{request_uri} = $request_uri;
226          $r->{error_status_text} = $res->status_line;
227      }      }
   }  
228    
229    $r .= '</ol>';      $r->{header_field} = [];
230    print STDOUT $r;      $res->scan (sub {
231  } # print_document_tree        push @{$r->{header_field}}, [$_[0], $_[1]];
232        });
233  sub get_node_path ($) {      $r->{header_status_code} = $res->code;
234    my $node = shift;      $r->{header_status_text} = $res->message;
235    my @r;    } else {
236    while (defined $node) {      $r->{s} = ''.$http->get_parameter ('s');
237      my $rs;      $r->{uri} = q<thismessage:/>;
238      if ($node->node_type == 1) {      $r->{request_uri} = q<thismessage:/>;
239        $rs = $node->manakai_local_name;      $r->{base_uri} = q<thismessage:/>;
240        $node = $node->parent_node;      $r->{charset} = ''.$http->get_parameter ('_charset_');
241      } elsif ($node->node_type == 2) {      $r->{charset} =~ s/\s+//g;
242        $rs = '@' . $node->manakai_local_name;      $r->{charset} = 'utf-8' if $r->{charset} eq '';
243        $node = $node->owner_element;      $r->{official_charset} = $r->{charset};
244      } elsif ($node->node_type == 3) {      $r->{header_field} = [];
245        $rs = '"' . $node->data . '"';  
246        $node = $node->parent_node;      require Whatpm::ContentType;
247      } elsif ($node->node_type == 9) {      ($r->{official_type}, $r->{media_type})
248        $rs = '';          = Whatpm::ContentType->get_sniffed_type
249        $node = $node->parent_node;              (get_file_head => sub {
250      } else {                 return substr $r->{s}, 0, shift;
251        $rs = '#' . $node->node_type;               },
252        $node = $node->parent_node;               http_content_type_byte => undef,
253      }               has_http_content_encoding => 0,
254      unshift @r, $rs;               supported_image_types => {});
255    }    }
256    return join '/', @r;  
257  } # get_node_path    my $input_format = $http->get_parameter ('i');
258      if (defined $input_format and length $input_format) {
259  sub get_node_link ($) {      $r->{media_type_overridden}
260    return qq[<a href="#node-@{[refaddr $_[0]]}">] .          = (not defined $r->{media_type} or $input_format ne $r->{media_type});
261        htescape (get_node_path ($_[0])) . qq[</a>];      $r->{media_type} = $input_format;
262  } # get_node_link    }
263      if (defined $r->{s} and not defined $r->{media_type}) {
264  {      $r->{media_type} = 'text/html';
265    my $Msg = {};      $r->{media_type_overridden} = 1;
266      }
267  sub load_text_catalog ($) {  
268    my $lang = shift; # MUST be a canonical lang name    if ($r->{media_type} eq 'text/xml') {
269    open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!";      unless (defined $r->{charset}) {
270    while (<$file>) {        $r->{charset} = 'us-ascii';
271      if (s/^([^;]+);([^;]*);//) {        $r->{official_charset} = $r->{charset};
272        my ($type, $cls, $msg) = ($1, $2, $_);      } elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') {
273        $msg =~ tr/\x0D\x0A//d;        $r->{charset_overridden} = 0;
274        $Msg->{$type} = [$cls, $msg];      }
275      }    }
276    
277      if (length $r->{s} > 1000_000) {
278        $r->{error_status_text} = 'Entity-body too large';
279        delete $r->{s};
280        return $r;
281      }
282    
283      $r->{inner_html_element} = $http->get_parameter ('e');
284    
285      return $r;
286    } # get_input_document
287    
288    package WDCC::LWPUA;
289    BEGIN { push our @ISA, 'LWP::UserAgent'; }
290    
291    sub redirect_ok {
292      my $ua = shift;
293      unless ($ua->SUPER::redirect_ok (@_)) {
294        return 0;
295      }
296    
297      my $uris = $_[1]->header ('Location');
298      return 0 unless $uris;
299      my $uri = $ua->{wdcc_dom}->create_uri_reference ($uris);
300      unless ({
301               http => 1,
302              }->{lc $uri->uri_scheme}) {
303        return 0;
304    }    }
305  } # load_text_catalog    unless ($ua->{wdcc_host_permit}->check ($uri->uri_host, $uri->uri_port || 80)) {
306        return 0;
 sub get_text ($) {  
   my ($type, $level) = @_;  
   $type = $level . ':' . $type if defined $level;  
   my @arg;  
   {  
     if (defined $Msg->{$type}) {  
       my $msg = $Msg->{$type}->[1];  
       $msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge;  
       return ($Msg->{$type}->[0], $msg);  
     } elsif ($type =~ s/:([^:]*)$//) {  
       unshift @arg, $1;  
       redo;  
     }  
307    }    }
308    return ('', htescape ($_[0]));    return 1;
309  } # get_text  } # redirect_ok
   
 }  
310    
311  =head1 AUTHOR  =head1 AUTHOR
312    
# Line 460  Wakaba <w@suika.fam.cx>. Line 314  Wakaba <w@suika.fam.cx>.
314    
315  =head1 LICENSE  =head1 LICENSE
316    
317  Copyright 2007 Wakaba <w@suika.fam.cx>  Copyright 2007-2008 Wakaba <w@suika.fam.cx>
318    
319  This library is free software; you can redistribute it  This library is free software; you can redistribute it
320  and/or modify it under the same terms as Perl itself.  and/or modify it under the same terms as Perl itself.

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.59

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24