/[suikacvs]/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.15 by wakaba, Sat Jul 21 04:58:17 2007 UTC revision 1.16 by wakaba, Sat Aug 11 13:54:55 2007 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];
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];
# Line 21  sub htescape ($) { Line 19  sub htescape ($) {
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    }    }
# Line 54  my $http = SuikaWiki::Input::HTTP->new; Line 51  my $http = SuikaWiki::Input::HTTP->new;
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">
# Line 67  my $http = SuikaWiki::Input::HTTP->new; Line 68  my $http = SuikaWiki::Input::HTTP->new;
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>
# Line 77  if (defined $input->{s}) { Line 79  if (defined $input->{s}) {
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  ];  ];
# Line 91  if (defined $input->{s}) { Line 95  if (defined $input->{s}) {
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">
# Line 117  if (defined $input->{s}) { Line 124  if (defined $input->{s}) {
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]);
# Line 124  if (defined $input->{s}) { Line 132  if (defined $input->{s}) {
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>
# Line 132  if (defined $input->{s}) { Line 142  if (defined $input->{s}) {
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}}) {
# Line 153  if (defined $input->{s}) { Line 166  if (defined $input->{s}) {
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>
# Line 202  if (defined $input->{s}) { Line 218  if (defined $input->{s}) {
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>
# Line 348  if (defined $input->{s}) { Line 367  if (defined $input->{s}) {
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 ($) {
# Line 564  sub get_text ($) { Line 589  sub get_text ($) {
589  sub get_input_document ($$) {  sub get_input_document ($$) {
590    my ($http, $dom) = @_;    my ($http, $dom) = @_;
591    
592    my $request_uri = $http->parameter ('uri');    my $request_uri = $http->get_parameter ('uri');
593    my $r = {};    my $r = {};
594    if (defined $request_uri and length $request_uri) {    if (defined $request_uri and length $request_uri) {
595      my $uri = $dom->create_uri_reference ($request_uri);      my $uri = $dom->create_uri_reference ($request_uri);
# Line 613  EOH Line 638  EOH
638      $ua->max_size (1000_000);      $ua->max_size (1000_000);
639      my $req = HTTP::Request->new (GET => $request_uri);      my $req = HTTP::Request->new (GET => $request_uri);
640      my $res = $ua->request ($req);      my $res = $ua->request ($req);
641      if ($res->is_success or $http->parameter ('error-page')) {      ## TODO: 401 sets |is_success| true.
642        if ($res->is_success or $http->get_parameter ('error-page')) {
643        $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!
644        $r->{uri} = $res->request->uri;        $r->{uri} = $res->request->uri;
645        $r->{request_uri} = $request_uri;        $r->{request_uri} = $request_uri;
# Line 628  EOH Line 654  EOH
654          $r->{charset} =~ tr/\\//d;          $r->{charset} =~ tr/\\//d;
655        }        }
656    
657        my $input_charset = $http->parameter ('charset');        my $input_charset = $http->get_parameter ('charset');
658        if (defined $input_charset and length $input_charset) {        if (defined $input_charset and length $input_charset) {
659          $r->{charset_overridden}          $r->{charset_overridden}
660              = (not defined $r->{charset} or $r->{charset} ne $input_charset);              = (not defined $r->{charset} or $r->{charset} ne $input_charset);
# Line 649  EOH Line 675  EOH
675      $r->{header_status_code} = $res->code;      $r->{header_status_code} = $res->code;
676      $r->{header_status_text} = $res->message;      $r->{header_status_text} = $res->message;
677    } else {    } else {
678      $r->{s} = ''.$http->parameter ('s');      $r->{s} = ''.$http->get_parameter ('s');
679      $r->{uri} = q<thismessage:/>;      $r->{uri} = q<thismessage:/>;
680      $r->{request_uri} = q<thismessage:/>;      $r->{request_uri} = q<thismessage:/>;
681      $r->{base_uri} = q<thismessage:/>;      $r->{base_uri} = q<thismessage:/>;
682      $r->{charset} = ''.$http->parameter ('_charset_');      $r->{charset} = ''.$http->get_parameter ('_charset_');
683      $r->{charset} =~ s/\s+//g;      $r->{charset} =~ s/\s+//g;
684      $r->{charset} = 'utf-8' if $r->{charset} eq '';      $r->{charset} = 'utf-8' if $r->{charset} eq '';
685      $r->{header_field} = [];      $r->{header_field} = [];
686    }    }
687    
688    my $input_format = $http->parameter ('i');    my $input_format = $http->get_parameter ('i');
689    if (defined $input_format and length $input_format) {    if (defined $input_format and length $input_format) {
690      $r->{media_type_overridden}      $r->{media_type_overridden}
691          = (not defined $r->{media_type} or $input_format ne $r->{media_type});          = (not defined $r->{media_type} or $input_format ne $r->{media_type});

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24