/[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.13 by wakaba, Tue Jul 17 13:52:54 2007 UTC
# Line 15  sub htescape ($) { Line 15  sub htescape ($) {
15    $s =~ s/</&lt;/g;    $s =~ s/</&lt;/g;
16    $s =~ s/>/&gt;/g;    $s =~ s/>/&gt;/g;
17    $s =~ s/"/&quot;/g;    $s =~ s/"/&quot;/g;
18    $s =~ s!([\x00-\x09\x0B-\x1F\x7F-\x80])!sprintf '<var>U+%04X</var>', ord $1!ge;    $s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{
19        sprintf '<var>U+%04X</var>', ord $1;
20      }ge;
21    return $s;    return $s;
22  } # htescape  } # htescape
23    
# Line 28  my $http = SuikaWiki::Input::HTTP->new; Line 30  my $http = SuikaWiki::Input::HTTP->new;
30      exit;      exit;
31    }    }
32    
33    my $input_format = $http->parameter ('i') || 'text/html';    binmode STDOUT, ':utf8';
   my $inner_html_element = $http->parameter ('e');  
   my $input_uri = 'thismessage:/';  
34    
35    my $s = $http->parameter ('s');    require Message::DOM::DOMImplementation;
36    if (length $s > 1000_000) {    my $dom = Message::DOM::DOMImplementation->new;
37      print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long";  
38      exit;    my $input = get_input_document ($http, $dom);
39    }    my $inner_html_element = $http->parameter ('e');
40    
41    load_text_catalog ('en'); ## TODO: conneg    load_text_catalog ('en'); ## TODO: conneg
42    
# Line 50  my $http = SuikaWiki::Input::HTTP->new; Line 50  my $http = SuikaWiki::Input::HTTP->new;
50  <link rel="stylesheet" href="../cc-style.css" type="text/css">  <link rel="stylesheet" href="../cc-style.css" type="text/css">
51  </head>  </head>
52  <body>  <body>
53  <h1>Web Document Conformance Checker (<em>beta</em>)</h1>  <h1><a href="../cc-interface">Web Document Conformance Checker</a>
54    (<em>beta</em>)</h1>
55    
56  <div id="document-info" class="section">  <div id="document-info" class="section">
57  <dl>  <dl>
58    <dt>Request URI</dt>
59        <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{request_uri}]}">@{[htescape $input->{request_uri}]}</a>&gt;</code></dd>
60  <dt>Document URI</dt>  <dt>Document URI</dt>
61      <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input_uri]}">@{[htescape $input_uri]}</a>&gt;</code></dd>      <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>  
62  ]; # no </dl> yet  ]; # no </dl> yet
63    push @nav, ['#document-info' => 'Information'];    push @nav, ['#document-info' => 'Information'];
64    
65    require Message::DOM::DOMImplementation;  if (defined $input->{s}) {
66    my $dom = Message::DOM::DOMImplementation->____new;  
67      print STDOUT qq[
68    <dt>Base URI</dt>
69        <dd><code class="URI" lang="">&lt;<a href="@{[htescape $input->{base_uri}]}">@{[htescape $input->{base_uri}]}</a>&gt;</code></dd>
70    <dt>Internet Media Type</dt>
71        <dd><code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code>
72        @{[$input->{media_type_overridden} ? '<em>(overridden)</em>' : '']}</dd>
73    <dt>Character Encoding</dt>
74        <dd>@{[defined $input->{charset} ? '<code class="charset" lang="en">'.htescape ($input->{charset}).'</code>' : '(none)']}
75        @{[$input->{charset_overridden} ? '<em>(overridden)</em>' : '']}</dd>
76    </dl>
77    </div>
78    ];
79    
80      print_http_header_section ($input);
81    
82    my $doc;    my $doc;
83    my $el;    my $el;
84    
85    if ($input_format eq 'text/html') {    if ($input->{media_type} eq 'text/html') {
86      require Encode;      require Encode;
87      require Whatpm::HTML;      require Whatpm::HTML;
       
     $s = Encode::decode ('utf-8', $s);  
88    
89      print STDOUT qq[      $input->{charset} ||= 'ISO-8859-1'; ## TODO: for now.
90  <dt>Character Encoding</dt>      
91      <dd>(none)</dd>      my $t = Encode::decode ($input->{charset}, $input->{s});
 </dl>  
 </div>  
92    
 <div id="source-string" class="section">  
 <h2>Document Source</h2>  
 ];  
     push @nav, ['#source-string' => 'Source'];  
     print_source_string (\$s);  
93      print STDOUT qq[      print STDOUT qq[
 </div>  
   
94  <div id="parse-errors" class="section">  <div id="parse-errors" class="section">
95  <h2>Parse Errors</h2>  <h2>Parse Errors</h2>
96    
97  <dl>  <dl>];
 ];  
98    push @nav, ['#parse-errors' => 'Parse Error'];    push @nav, ['#parse-errors' => 'Parse Error'];
99    
100    my $onerror = sub {    my $onerror = sub {
101      my (%opt) = @_;      my (%opt) = @_;
102      my ($cls, $msg) = get_text ($opt{type}, $opt{level});      my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});
103      if ($opt{column} > 0) {      if ($opt{column} > 0) {
104        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n];        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n];
105      } else {      } else {
106        $opt{line} = $opt{line} - 1 || 1;        $opt{line} = $opt{line} - 1 || 1;
107        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n];        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n];
108      }      }
109      $opt{type} =~ tr/ /-/;      $type =~ tr/ /-/;
110      $opt{type} =~ s/\|/%7C/g;      $type =~ s/\|/%7C/g;
111      $msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]];      $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];
112      print STDOUT qq[<dd class="$cls">$msg</dd>\n];      print STDOUT qq[<dd class="$cls">$msg</dd>\n];
113    };    };
114    
# Line 112  my $http = SuikaWiki::Input::HTTP->new; Line 116  my $http = SuikaWiki::Input::HTTP->new;
116    if (defined $inner_html_element and length $inner_html_element) {    if (defined $inner_html_element and length $inner_html_element) {
117      $el = $doc->create_element_ns      $el = $doc->create_element_ns
118          ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]);          ('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]);
119      Whatpm::HTML->set_inner_html ($el, $s, $onerror);      Whatpm::HTML->set_inner_html ($el, $t, $onerror);
120    } else {    } else {
121      Whatpm::HTML->parse_string ($s => $doc, $onerror);      Whatpm::HTML->parse_string ($t => $doc, $onerror);
122    }    }
123    
124    print STDOUT qq[    print STDOUT qq[</dl>
 </dl>  
125  </div>  </div>
126  ];  ];
   } elsif ($input_format eq 'application/xhtml+xml') {  
     require Message::DOM::XMLParserTemp;  
     require Encode;  
       
     my $t = Encode::decode ('utf-8', $s);  
127    
128      print STDOUT qq[      print_source_string_section (\($input->{s}), $input->{charset});
129  <dt>Character Encoding</dt>    } elsif ({
130      <dd>(none)</dd>              'text/xml' => 1,
131  </dl>              'application/xhtml+xml' => 1,
132  </div>              'application/xml' => 1,
133               }->{$input->{media_type}}) {
134        require Message::DOM::XMLParserTemp;
135    
 <div id="source-string" class="section">  
 <h2>Document Source</h2>  
 ];  
     push @nav, ['#source-string' => 'Source'];  
     print_source_string (\$t);  
136      print STDOUT qq[      print STDOUT qq[
 </div>  
   
137  <div id="parse-errors" class="section">  <div id="parse-errors" class="section">
138  <h2>Parse Errors</h2>  <h2>Parse Errors</h2>
139    
# Line 156  my $http = SuikaWiki::Input::HTTP->new; Line 149  my $http = SuikaWiki::Input::HTTP->new;
149      return 1;      return 1;
150    };    };
151    
152    open my $fh, '<', \$s;    open my $fh, '<', \($input->{s});
153    $doc = Message::DOM::XMLParserTemp->parse_byte_stream    $doc = Message::DOM::XMLParserTemp->parse_byte_stream
154        ($fh => $dom, $onerror, charset => 'utf-8');        ($fh => $dom, $onerror, charset => $input->{charset});
155    
156      print STDOUT qq[</dl>      print STDOUT qq[</dl>
157  </div>  </div>
158    
159  ];  ];
160        print_source_string_section (\($input->{s}), $doc->input_encoding);
161    } else {    } else {
162        ## TODO: Change HTTP status code??
163      print STDOUT qq[      print STDOUT qq[
 </dl>  
 </div>  
   
164  <div id="result-summary" class="section">  <div id="result-summary" class="section">
165  <p><em>Media type <code class="MIME" lang="en">@{[htescape $input_format]}</code> is not supported!</em></p>  <p><em>Media type <code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> is not supported!</em></p>
166  </div>  </div>
167  ];  ];
168      push @nav, ['#result-summary' => 'Result'];      push @nav, ['#result-summary' => 'Result'];
# Line 197  my $http = SuikaWiki::Input::HTTP->new; Line 190  my $http = SuikaWiki::Input::HTTP->new;
190      require Whatpm::ContentChecker;      require Whatpm::ContentChecker;
191      my $onerror = sub {      my $onerror = sub {
192        my %opt = @_;        my %opt = @_;
193        my ($cls, $msg) = get_text ($opt{type}, $opt{level});        my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});
194        $opt{type} = $opt{level} . ':' . $opt{type} if defined $opt{level};        $type =~ tr/ /-/;
195        $opt{type} =~ tr/ /-/;        $type =~ s/\|/%7C/g;
196        $opt{type} =~ s/\|/%7C/g;        $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];
       $msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]];  
197        print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) .        print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) .
198            qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n";            qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n";
199      };      };
# Line 236  my $http = SuikaWiki::Input::HTTP->new; Line 228  my $http = SuikaWiki::Input::HTTP->new;
228          $i++;          $i++;
229          print STDOUT qq[<div class="section" id="table-$i"><h3>] .          print STDOUT qq[<div class="section" id="table-$i"><h3>] .
230              get_node_link ($table_el) . q[</h3>];              get_node_link ($table_el) . q[</h3>];
231            
232            ## TODO: Make |ContentChecker| return |form_table| result
233            ## so that this script don't have to run the algorithm twice.
234          my $table = Whatpm::HTMLTable->form_table ($table_el);          my $table = Whatpm::HTMLTable->form_table ($table_el);
235                    
236          for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) {          for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) {
# Line 258  my $http = SuikaWiki::Input::HTTP->new; Line 252  my $http = SuikaWiki::Input::HTTP->new;
252              for (@$_) {              for (@$_) {
253                $_->{id} = refaddr $_->{element} if defined $_->{element};                $_->{id} = refaddr $_->{element} if defined $_->{element};
254                delete $_->{element};                delete $_->{element};
255                  $_->{is_header} = $_->{is_header} ? 1 : 0;
256              }              }
257            }            }
258          }          }
# Line 270  my $http = SuikaWiki::Input::HTTP->new; Line 265  my $http = SuikaWiki::Input::HTTP->new;
265        print STDOUT qq[</div>];        print STDOUT qq[</div>];
266      }      }
267    
268        if (keys %{$elements->{id}}) {
269          print STDOUT qq[
270    <div id="identifiers" class="section">
271    <h2>Identifiers</h2>
272    
273    <dl>
274    ];
275          for my $id (sort {$a cmp $b} keys %{$elements->{id}}) {
276            print STDOUT qq[<dt>@{[htescape $id]}</dt>];
277            for (@{$elements->{id}->{$id}}) {
278              print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>];
279            }
280          }
281          print STDOUT qq[</dl></div>];
282        }
283    
284      if (keys %{$elements->{term}}) {      if (keys %{$elements->{term}}) {
285        print STDOUT qq[        print STDOUT qq[
286  <div id="terms" class="section">  <div id="terms" class="section">
# Line 288  my $http = SuikaWiki::Input::HTTP->new; Line 299  my $http = SuikaWiki::Input::HTTP->new;
299    }    }
300    
301    ## TODO: Show result    ## TODO: Show result
302    } else {
303      print STDOUT qq[
304    </dl>
305    </div>
306    
307    <div class="section" id="result-summary">
308    <p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p>
309    </div>
310    ];
311      push @nav, ['#result-summary' => 'Result'];
312    
313    }
314    
315    print STDOUT qq[    print STDOUT qq[
316  <ul class="navigation" id="nav-items">  <ul class="navigation" id="nav-items">
# Line 303  my $http = SuikaWiki::Input::HTTP->new; Line 326  my $http = SuikaWiki::Input::HTTP->new;
326    
327  exit;  exit;
328    
329  sub print_source_string ($) {  sub print_http_header_section ($) {
330    my $s = $_[0];    my $input = shift;
331    my $i = 1;    return unless defined $input->{header_status_code} or
332    print STDOUT qq[<ol lang="">\n];        defined $input->{header_status_text} or
333          @{$input->{header_field}};
334      
335      push @nav, ['#source-header' => 'HTTP Header'];
336      print STDOUT qq[<div id="source-header" class="section">
337    <h2>HTTP Header</h2>
338    
339    <p><strong>Note</strong>: Due to the limitation of the
340    network library in use, the content of this section might
341    not be the real header.</p>
342    
343    <table><tbody>
344    ];
345    
346      if (defined $input->{header_status_code}) {
347        print STDOUT qq[<tr><th scope="row">Status code</th>];
348        print STDOUT qq[<td><code>@{[htescape ($input->{header_status_code})]}</code></td></tr>];
349      }
350      if (defined $input->{header_status_text}) {
351        print STDOUT qq[<tr><th scope="row">Status text</th>];
352        print STDOUT qq[<td><code>@{[htescape ($input->{header_status_text})]}</code></td></tr>];
353      }
354      
355      for (@{$input->{header_field}}) {
356        print STDOUT qq[<tr><th scope="row"><code>@{[htescape ($_->[0])]}</code></th>];
357        print STDOUT qq[<td><code>@{[htescape ($_->[1])]}</code></td></tr>];
358      }
359    
360      print STDOUT qq[</tbody></table></div>];
361    } # print_http_header_section
362    
363    sub print_source_string_section ($$) {
364      require Encode;
365      my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name
366      return unless $enc;
367    
368      my $s = \($enc->decode (${$_[0]}));
369      my $i = 1;                            
370      push @nav, ['#source-string' => 'Source'];
371      print STDOUT qq[<div id="source-string" class="section">
372    <h2>Document Source</h2>
373    <ol lang="">\n];
374    if (length $$s) {    if (length $$s) {
375      while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {      while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {
376        print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";        print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";
# Line 318  sub print_source_string ($) { Line 382  sub print_source_string ($) {
382    } else {    } else {
383      print STDOUT q[<li id="line-1"></li>];      print STDOUT q[<li id="line-1"></li>];
384    }    }
385    print STDOUT "</ol>";    print STDOUT "</ol></div>";
386  } # print_input_string  } # print_input_string_section
387    
388  sub print_document_tree ($) {  sub print_document_tree ($) {
389    my $node = shift;    my $node = shift;
# Line 367  sub print_document_tree ($) { Line 431  sub print_document_tree ($) {
431        $r .= qq[<ul class="attributes">];        $r .= qq[<ul class="attributes">];
432        $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>];
433        $r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>];        $r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>];
434          unless ($child->manakai_is_html) {
435            $r .= qq[<li>XML version = <code>@{[htescape ($child->xml_version)]}</code></li>];
436            if (defined $child->xml_encoding) {
437              $r .= qq[<li>XML encoding = <code>@{[htescape ($child->xml_encoding)]}</code></li>];
438            } else {
439              $r .= qq[<li>XML encoding = (null)</li>];
440            }
441            $r .= qq[<li>XML standalone = @{[$child->xml_standalone ? 'true' : 'false']}</li>];
442          }
443        $r .= qq[</ul>];        $r .= qq[</ul>];
444        if ($child->has_child_nodes) {        if ($child->has_child_nodes) {
445          $r .= '<ol class="children">';          $r .= '<ol class="children">';
# Line 404  sub get_node_path ($) { Line 477  sub get_node_path ($) {
477        $rs = '"' . $node->data . '"';        $rs = '"' . $node->data . '"';
478        $node = $node->parent_node;        $node = $node->parent_node;
479      } elsif ($node->node_type == 9) {      } elsif ($node->node_type == 9) {
480          @r = ('') unless @r;
481        $rs = '';        $rs = '';
482        $node = $node->parent_node;        $node = $node->parent_node;
483      } else {      } else {
# Line 442  sub get_text ($) { Line 516  sub get_text ($) {
516    {    {
517      if (defined $Msg->{$type}) {      if (defined $Msg->{$type}) {
518        my $msg = $Msg->{$type}->[1];        my $msg = $Msg->{$type}->[1];
519        $msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge;        $msg =~ s{<var>\$([0-9]+)</var>}{
520        return ($Msg->{$type}->[0], $msg);          defined $arg[$1] ? htescape ($arg[$1]) : '(undef)';
521          }ge;
522          return ($type, $Msg->{$type}->[0], $msg);
523      } elsif ($type =~ s/:([^:]*)$//) {      } elsif ($type =~ s/:([^:]*)$//) {
524        unshift @arg, $1;        unshift @arg, $1;
525        redo;        redo;
526      }      }
527    }    }
528    return ('', htescape ($_[0]));    return ($type, '', htescape ($_[0]));
529  } # get_text  } # get_text
530    
531  }  }
532    
533    sub get_input_document ($$) {
534      my ($http, $dom) = @_;
535    
536      my $request_uri = $http->parameter ('uri');
537      my $r = {};
538      if (defined $request_uri and length $request_uri) {
539        my $uri = $dom->create_uri_reference ($request_uri);
540        unless ({
541                 http => 1,
542                }->{lc $uri->uri_scheme}) {
543          return {uri => $request_uri, request_uri => $request_uri,
544                  error_status_text => 'URI scheme not allowed'};
545        }
546    
547        require Message::Util::HostPermit;
548        my $host_permit = new Message::Util::HostPermit;
549        $host_permit->add_rule (<<EOH);
550    Allow host=suika port=80
551    Deny host=suika
552    Allow host=suika.fam.cx port=80
553    Deny host=suika.fam.cx
554    Deny host=localhost
555    Deny host=*.localdomain
556    Deny ipv4=0.0.0.0/8
557    Deny ipv4=10.0.0.0/8
558    Deny ipv4=127.0.0.0/8
559    Deny ipv4=169.254.0.0/16
560    Deny ipv4=172.0.0.0/11
561    Deny ipv4=192.0.2.0/24
562    Deny ipv4=192.88.99.0/24
563    Deny ipv4=192.168.0.0/16
564    Deny ipv4=198.18.0.0/15
565    Deny ipv4=224.0.0.0/4
566    Deny ipv4=255.255.255.255/32
567    Deny ipv6=0::0/0
568    Allow host=*
569    EOH
570        unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) {
571          return {uri => $request_uri, request_uri => $request_uri,
572                  error_status_text => 'Connection to the host is forbidden'};
573        }
574    
575        require LWP::UserAgent;
576        my $ua = WDCC::LWPUA->new;
577        $ua->{wdcc_dom} = $dom;
578        $ua->{wdcc_host_permit} = $host_permit;
579        $ua->agent ('Mozilla'); ## TODO: for now.
580        $ua->parse_head (0);
581        $ua->protocols_allowed ([qw/http/]);
582        $ua->max_size (1000_000);
583        my $req = HTTP::Request->new (GET => $request_uri);
584        my $res = $ua->request ($req);
585        if ($res->is_success or $http->parameter ('error-page')) {
586          $r->{base_uri} = $res->base; ## NOTE: It does check |Content-Base|, |Content-Location|, and <base>. ## TODO: Use our own code!
587          $r->{uri} = $res->request->uri;
588          $r->{request_uri} = $request_uri;
589    
590          ## TODO: More strict parsing...
591          my $ct = $res->header ('Content-Type');
592          if (defined $ct and $ct =~ m#^([0-9A-Za-z._+-]+/[0-9A-Za-z._+-]+)#) {
593            $r->{media_type} = lc $1;
594          }
595          if (defined $ct and $ct =~ /;\s*charset\s*=\s*"?(\S+)"?/i) {
596            $r->{charset} = lc $1;
597            $r->{charset} =~ tr/\\//d;
598          }
599    
600          my $input_charset = $http->parameter ('charset');
601          if (defined $input_charset and length $input_charset) {
602            $r->{charset_overridden}
603                = (not defined $r->{charset} or $r->{charset} ne $input_charset);
604            $r->{charset} = $input_charset;
605          }
606    
607          $r->{s} = ''.$res->content;
608        } else {
609          $r->{uri} = $res->request->uri;
610          $r->{request_uri} = $request_uri;
611          $r->{error_status_text} = $res->status_line;
612        }
613    
614        $r->{header_field} = [];
615        $res->scan (sub {
616          push @{$r->{header_field}}, [$_[0], $_[1]];
617        });
618        $r->{header_status_code} = $res->code;
619        $r->{header_status_text} = $res->message;
620      } else {
621        $r->{s} = ''.$http->parameter ('s');
622        $r->{uri} = q<thismessage:/>;
623        $r->{request_uri} = q<thismessage:/>;
624        $r->{base_uri} = q<thismessage:/>;
625        $r->{charset} = ''.$http->parameter ('_charset_');
626        $r->{charset} =~ s/\s+//g;
627        $r->{charset} = 'utf-8' if $r->{charset} eq '';
628        $r->{header_field} = [];
629      }
630    
631      my $input_format = $http->parameter ('i');
632      if (defined $input_format and length $input_format) {
633        $r->{media_type_overridden}
634            = (not defined $r->{media_type} or $input_format ne $r->{media_type});
635        $r->{media_type} = $input_format;
636      }
637      if (defined $r->{s} and not defined $r->{media_type}) {
638        $r->{media_type} = 'text/html';
639        $r->{media_type_overridden} = 1;
640      }
641    
642      if ($r->{media_type} eq 'text/xml') {
643        unless (defined $r->{charset}) {
644          $r->{charset} = 'us-ascii';
645        } elsif ($r->{charset_overridden} and $r->{charset} eq 'us-ascii') {
646          $r->{charset_overridden} = 0;
647        }
648      }
649    
650      if (length $r->{s} > 1000_000) {
651        $r->{error_status_text} = 'Entity-body too large';
652        delete $r->{s};
653        return $r;
654      }
655    
656      return $r;
657    } # get_input_document
658    
659    package WDCC::LWPUA;
660    BEGIN { push our @ISA, 'LWP::UserAgent'; }
661    
662    sub redirect_ok {
663      my $ua = shift;
664      unless ($ua->SUPER::redirect_ok (@_)) {
665        return 0;
666      }
667    
668      my $uris = $_[1]->header ('Location');
669      return 0 unless $uris;
670      my $uri = $ua->{wdcc_dom}->create_uri_reference ($uris);
671      unless ({
672               http => 1,
673              }->{lc $uri->uri_scheme}) {
674        return 0;
675      }
676      unless ($ua->{wdcc_host_permit}->check ($uri->uri_host, $uri->uri_port || 80)) {
677        return 0;
678      }
679      return 1;
680    } # redirect_ok
681    
682  =head1 AUTHOR  =head1 AUTHOR
683    
684  Wakaba <w@suika.fam.cx>.  Wakaba <w@suika.fam.cx>.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24