/[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.53 by wakaba, Sun Jul 20 14:58:24 2008 UTC revision 1.54 by wakaba, Sun Jul 20 16:53:10 2008 UTC
# Line 106  my $out; Line 106  my $out;
106      $out->end_section;      $out->end_section;
107    
108      my $result = WebHACC::Result->new;      my $result = WebHACC::Result->new;
109        $result->output ($out);
110      $result->{conforming_min} = 1;      $result->{conforming_min} = 1;
111      $result->{conforming_max} = 1;      $result->{conforming_max} = 1;
112      check_and_print ($input => $result => $out);      check_and_print ($input => $result => $out);
113      print_result_section ($result);      $result->generate_result_section;
114    } else {    } else {
115      $out->html ('</dl>');      $out->html ('</dl>');
116      $out->end_section;      $out->end_section;
117      print_result_input_error_section ($input);  
118        my $result = WebHACC::Result->new;
119        $result->output ($out);
120        $result->{conforming_min} = 0;
121        $result->{conforming_max} = 1;
122    
123        $input->generate_transfer_sections ($result);
124        $result->generate_result_section;
125    }    }
126    
127    $out->nav_list;    $out->nav_list;
# Line 121  my $out; Line 129  my $out;
129    exit;    exit;
130  }  }
131    
 sub add_error ($$$) {  
   my ($layer, $err, $result) = @_;  
   if (defined $err->{level}) {  
     if ($err->{level} eq 's') {  
       $result->{$layer}->{should}++;  
       $result->{$layer}->{score_min} -= 2;  
       $result->{conforming_min} = 0;  
     } elsif ($err->{level} eq 'w' or $err->{level} eq 'g') {  
       $result->{$layer}->{warning}++;  
     } elsif ($err->{level} eq 'u' or $err->{level} eq 'unsupported') {  
       $result->{$layer}->{unsupported}++;  
       $result->{unsupported} = 1;  
     } elsif ($err->{level} eq 'i') {  
       #  
     } else {  
       $result->{$layer}->{must}++;  
       $result->{$layer}->{score_max} -= 2;  
       $result->{$layer}->{score_min} -= 2;  
       $result->{conforming_min} = 0;  
       $result->{conforming_max} = 0;  
     }  
   } else {  
     $result->{$layer}->{must}++;  
     $result->{$layer}->{score_max} -= 2;  
     $result->{$layer}->{score_min} -= 2;  
     $result->{conforming_min} = 0;  
     $result->{conforming_max} = 0;  
   }  
 } # add_error  
   
132  sub check_and_print ($$$) {  sub check_and_print ($$$) {
133    my ($input, $result, $out) = @_;    my ($input, $result, $out) = @_;
134    my $original_input = $out->input;    my $original_input = $out->input;
135    $out->input ($input);    $out->input ($input);
136    
137    print_http_header_section ($input, $result);    $input->generate_transfer_sections ($result);
138    
139    my @subdoc;    my @subdoc;
140    
# Line 249  sub check_and_print ($$$) { Line 227  sub check_and_print ($$$) {
227    $out->input ($original_input);    $out->input ($original_input);
228  } # check_and_print  } # check_and_print
229    
 sub print_http_header_section ($$) {  
   my ($input, $result) = @_;  
   return unless defined $input->{header_status_code} or  
       defined $input->{header_status_text} or  
       @{$input->{header_field} or []};  
     
   $out->start_section (id => 'source-header', title => 'HTTP Header');  
   print STDOUT qq[<p><strong>Note</strong>: Due to the limitation of the  
 network library in use, the content of this section might  
 not be the real header.</p>  
   
 <table><tbody>  
 ];  
   
   if (defined $input->{header_status_code}) {  
     print STDOUT qq[<tr><th scope="row">Status code</th>];  
     print STDOUT qq[<td>];  
     $out->code ($input->{header_status_code});  
   }  
   if (defined $input->{header_status_text}) {  
     print STDOUT qq[<tr><th scope="row">Status text</th>];  
     print STDOUT qq[<td>];  
     $out->code ($input->{header_status_text});  
   }  
     
   for (@{$input->{header_field}}) {  
     print STDOUT qq[<tr><th scope="row">];  
     $out->code ($_->[0]);  
     print STDOUT qq[<td>];  
     $out->code ($_->[1]);  
   }  
   
   print STDOUT qq[</tbody></table>];  
   
   $out->end_section;  
 } # print_http_header_section  
   
230  sub print_table_section ($$) {  sub print_table_section ($$) {
231    my ($input, $tables) = @_;    my ($input, $tables) = @_;
232        
# Line 422  sub get_rdf_resource_html ($) { Line 363  sub get_rdf_resource_html ($) {
363    }    }
364  } # get_rdf_resource_html  } # get_rdf_resource_html
365    
 sub print_result_section ($) {  
   my $result = shift;  
   
   $out->start_section (id => 'result-summary',  
                        title => 'Result');  
   
   if ($result->{unsupported} and $result->{conforming_max}) {    
     print STDOUT qq[<p class=uncertain id=result-para>The conformance  
         checker cannot decide whether the document is conforming or  
         not, since the document contains one or more unsupported  
         features.  The document might or might not be conforming.</p>];  
   } elsif ($result->{conforming_min}) {  
     print STDOUT qq[<p class=PASS id=result-para>No conformance-error is  
         found in this document.</p>];  
   } elsif ($result->{conforming_max}) {  
     print STDOUT qq[<p class=SEE-RESULT id=result-para>This document  
         is <strong>likely <em>non</em>-conforming</strong>, but in rare case  
         it might be conforming.</p>];  
   } else {  
     print STDOUT qq[<p class=FAIL id=result-para>This document is  
         <strong><em>non</em>-conforming</strong>.</p>];  
   }  
   
   print STDOUT qq[<table>  
 <colgroup><col><colgroup><col><col><col><colgroup><col>  
 <thead>  
 <tr><th scope=col></th>  
 <th scope=col><a href="../error-description#level-m"><em class=rfc2119>MUST</em>‐level  
 Errors</a></th>  
 <th scope=col><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>‐level  
 Errors</a></th>  
 <th scope=col><a href="../error-description#level-w">Warnings</a></th>  
 <th scope=col>Score</th></tr></thead><tbody>];  
   
   my $must_error = 0;  
   my $should_error = 0;  
   my $warning = 0;  
   my $score_min = 0;  
   my $score_max = 0;  
   my $score_base = 20;  
   my $score_unit = $score_base / 100;  
   for (  
     [Transfer => 'transfer', ''],  
     [Character => 'char', ''],  
     [Syntax => 'syntax', '#parse-errors'],  
     [Structure => 'structure', '#document-errors'],  
   ) {  
     $must_error += ($result->{$_->[1]}->{must} += 0);  
     $should_error += ($result->{$_->[1]}->{should} += 0);  
     $warning += ($result->{$_->[1]}->{warning} += 0);  
     $score_min += (($result->{$_->[1]}->{score_min} *= $score_unit) += $score_base);  
     $score_max += (($result->{$_->[1]}->{score_max} *= $score_unit) += $score_base);  
   
     my $uncertain = $result->{$_->[1]}->{unsupported} ? '?' : '';  
     my $label = $_->[0];  
     if ($result->{$_->[1]}->{must} or  
         $result->{$_->[1]}->{should} or  
         $result->{$_->[1]}->{warning} or  
         $result->{$_->[1]}->{unsupported}) {  
       $label = qq[<a href="$_->[2]">$label</a>];  
     }  
   
     print STDOUT qq[<tr class="@{[$uncertain ? 'uncertain' : '']}"><th scope=row>$label</th><td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{must}$uncertain</td><td class="@{[$result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">$result->{$_->[1]}->{should}$uncertain</td><td>$result->{$_->[1]}->{warning}$uncertain</td>];  
     if ($uncertain) {  
       print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">&#x2212;&#x221E;..$result->{$_->[1]}->{score_max}];  
     } elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) {  
       print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}];  
     } else {  
       print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}];  
     }  
     print qq[ / 20];  
   }  
   
   $score_max += $score_base;  
   
   print STDOUT qq[  
 <tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>&#x2212;&#x221E;..$score_base / 20  
 </tbody>  
 <tfoot><tr class=uncertain><th scope=row>Total</th>  
 <td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td>  
 <td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td>  
 <td>$warning?</td>  
 <td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>&#x2212;&#x221E;..$score_max</strong> / 100  
 </table>  
   
 <p><strong>Important</strong>: This conformance checking service  
 is <em>under development</em>.  The result above might be <em>wrong</em>.</p>];  
   $out->end_section;  
 } # print_result_section  
   
 sub print_result_input_error_section ($) {  
   my $input = shift;  
   $out->start_section (id => 'result-summary', title => 'Result');  
   print STDOUT qq[  
 <p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p>];  
   $out->end_section;  
 } # print_result_input_error_section  
   
366  {  {
367    my $Msg = {};    my $Msg = {};
368    
# Line 581  sub get_text ($;$$) { Line 424  sub get_text ($;$$) {
424  sub get_input_document ($$) {  sub get_input_document ($$) {
425    my ($http, $dom) = @_;    my ($http, $dom) = @_;
426    
427    my $request_uri = $http->get_parameter ('uri');    require Encode;
428      my $request_uri = Encode::decode ('utf-8', $http->get_parameter ('uri'));
429    my $r = WebHACC::Input->new;    my $r = WebHACC::Input->new;
430    if (defined $request_uri and length $request_uri) {    if (defined $request_uri and length $request_uri) {
431      my $uri = $dom->create_uri_reference ($request_uri);      my $uri = $dom->create_uri_reference ($request_uri);
432      unless ({      unless ({
433               http => 1,               http => 1,
434              }->{lc $uri->uri_scheme}) {              }->{lc $uri->uri_scheme}) {
435        return {uri => $request_uri, request_uri => $request_uri,        $r = WebHACC::Input::Error->new;
436                error_status_text => 'URI scheme not allowed'};        $r->{uri} = $request_uri;
437          $r->{request_uri} = $request_uri;
438          $r->{error_status_text} = 'URL scheme not allowed';
439      }      }
440    
441      require Message::Util::HostPermit;      require Message::Util::HostPermit;
# Line 616  Deny ipv6=0::0/0 Line 462  Deny ipv6=0::0/0
462  Allow host=*  Allow host=*
463  EOH  EOH
464      unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) {      unless ($host_permit->check ($uri->uri_host, $uri->uri_port || 80)) {
465        return {uri => $request_uri, request_uri => $request_uri,        my $r = WebHACC::Input::Error->new;
466                error_status_text => 'Connection to the host is forbidden'};        $r->{uri} = $request_uri;
467          $r->{request_uri} = $request_uri;
468          $r->{error_status_text} = 'Connection to the host is forbidden';
469          return $r;
470      }      }
471    
472      require LWP::UserAgent;      require LWP::UserAgent;

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24