Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine/CGI.pm |
Statements | Executed 111 statements in 3.76ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 3.90ms | 15.4ms | BEGIN@22 | Foswiki::Engine::CGI::
1 | 1 | 1 | 2.89ms | 3.02ms | BEGIN@24 | Foswiki::Engine::CGI::
1 | 1 | 1 | 2.45ms | 3.01ms | BEGIN@18 | Foswiki::Engine::CGI::
1 | 1 | 1 | 637µs | 781µs | BEGIN@23 | Foswiki::Engine::CGI::
2 | 2 | 1 | 451µs | 451µs | CORE:print (opcode) | Foswiki::Engine::CGI::
1 | 1 | 1 | 308µs | 919µs | prepareHeaders | Foswiki::Engine::CGI::
1 | 1 | 1 | 107µs | 195µs | preparePath | Foswiki::Engine::CGI::
1 | 1 | 1 | 103µs | 265s | run | Foswiki::Engine::CGI::
1 | 1 | 1 | 96µs | 122µs | prepareConnection | Foswiki::Engine::CGI::
1 | 1 | 1 | 67µs | 1.70ms | finalizeHeaders | Foswiki::Engine::CGI::
31 | 1 | 1 | 66µs | 66µs | CORE:match (opcode) | Foswiki::Engine::CGI::
10 | 3 | 1 | 49µs | 49µs | CORE:subst (opcode) | Foswiki::Engine::CGI::
1 | 1 | 1 | 35µs | 72µs | write | Foswiki::Engine::CGI::
1 | 1 | 1 | 33µs | 42µs | finalizeUploads | Foswiki::Engine::CGI::
1 | 1 | 1 | 29µs | 38µs | BEGIN@15 | Foswiki::Engine::CGI::
1 | 1 | 1 | 24µs | 24µs | CORE:regcomp (opcode) | Foswiki::Engine::CGI::
1 | 1 | 1 | 22µs | 45µs | BEGIN@16 | Foswiki::Engine::CGI::
1 | 1 | 1 | 18µs | 57µs | BEGIN@21 | Foswiki::Engine::CGI::
1 | 1 | 1 | 8µs | 8µs | prepareBody | Foswiki::Engine::CGI::
1 | 1 | 1 | 8µs | 8µs | prepareQueryParameters | Foswiki::Engine::CGI::
1 | 1 | 1 | 7µs | 7µs | prepareBodyParameters | Foswiki::Engine::CGI::
1 | 1 | 1 | 7µs | 7µs | prepareUploads | Foswiki::Engine::CGI::
2 | 1 | 1 | 7µs | 7µs | CORE:substcont (opcode) | Foswiki::Engine::CGI::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+!! package Foswiki::Engine::CGI | ||||
6 | |||||
7 | Class that implements default CGI behavior. | ||||
8 | |||||
9 | Refer to Foswiki::Engine documentation for explanation about methods below. | ||||
10 | |||||
11 | =cut | ||||
12 | |||||
13 | package Foswiki::Engine::CGI; | ||||
14 | |||||
15 | 2 | 50µs | 2 | 46µs | # spent 38µs (29+9) within Foswiki::Engine::CGI::BEGIN@15 which was called:
# once (29µs+9µs) by Foswiki::BEGIN@1 at line 15 # spent 38µs making 1 call to Foswiki::Engine::CGI::BEGIN@15
# spent 9µs making 1 call to strict::import |
16 | 2 | 48µs | 2 | 69µs | # spent 45µs (22+23) within Foswiki::Engine::CGI::BEGIN@16 which was called:
# once (22µs+23µs) by Foswiki::BEGIN@1 at line 16 # spent 45µs making 1 call to Foswiki::Engine::CGI::BEGIN@16
# spent 23µs making 1 call to warnings::import |
17 | |||||
18 | 2 | 188µs | 1 | 3.01ms | # spent 3.01ms (2.45+557µs) within Foswiki::Engine::CGI::BEGIN@18 which was called:
# once (2.45ms+557µs) by Foswiki::BEGIN@1 at line 18 # spent 3.01ms making 1 call to Foswiki::Engine::CGI::BEGIN@18 |
19 | 1 | 12µs | our @ISA = ('Foswiki::Engine'); | ||
20 | |||||
21 | 2 | 45µs | 2 | 96µs | # spent 57µs (18+39) within Foswiki::Engine::CGI::BEGIN@21 which was called:
# once (18µs+39µs) by Foswiki::BEGIN@1 at line 21 # spent 57µs making 1 call to Foswiki::Engine::CGI::BEGIN@21
# spent 39µs making 1 call to Assert::import |
22 | 2 | 152µs | 1 | 15.4ms | # spent 15.4ms (3.90+11.5) within Foswiki::Engine::CGI::BEGIN@22 which was called:
# once (3.90ms+11.5ms) by Foswiki::BEGIN@1 at line 22 # spent 15.4ms making 1 call to Foswiki::Engine::CGI::BEGIN@22 |
23 | 2 | 146µs | 1 | 781µs | # spent 781µs (637+144) within Foswiki::Engine::CGI::BEGIN@23 which was called:
# once (637µs+144µs) by Foswiki::BEGIN@1 at line 23 # spent 781µs making 1 call to Foswiki::Engine::CGI::BEGIN@23 |
24 | 2 | 1.79ms | 1 | 3.02ms | # spent 3.02ms (2.89+128µs) within Foswiki::Engine::CGI::BEGIN@24 which was called:
# once (2.89ms+128µs) by Foswiki::BEGIN@1 at line 24 # spent 3.02ms making 1 call to Foswiki::Engine::CGI::BEGIN@24 |
25 | |||||
26 | # spent 265s (103µs+265) within Foswiki::Engine::CGI::run which was called:
# once (103µs+265s) by main::RUNTIME at line 29 of view | ||||
27 | 4 | 44µs | my $this = shift; | ||
28 | unless ( $Foswiki::cfg{isVALID} ) { | ||||
29 | print STDOUT "Content-type: text/html\n\n"; | ||||
30 | print STDOUT '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' | ||||
31 | . "\n " | ||||
32 | . '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n"; | ||||
33 | print STDOUT | ||||
34 | "<html><head></head><body><h1>Foswiki Configuration Error</h1><br>Please run <code>configure</code> to create a valid configuration<br />\n"; | ||||
35 | print STDOUT | ||||
36 | "If you've already done this, then your <code>lib/LocalSite.cfg</code> is most likely damaged\n</body></html>"; | ||||
37 | exit 1; | ||||
38 | } | ||||
39 | 1 | 6.28ms | my $req = $this->prepare; # spent 6.28ms making 1 call to Foswiki::Engine::prepare | ||
40 | 2 | 62µs | 1 | 4µs | if ( UNIVERSAL::isa( $req, 'Foswiki::Request' ) ) { # spent 4µs making 1 call to UNIVERSAL::isa |
41 | 1 | 265s | my $res = Foswiki::UI::handleRequest($req); # spent 265s making 1 call to Foswiki::UI::handleRequest | ||
42 | 1 | 2.00ms | $this->finalize( $res, $req ); # spent 2.00ms making 1 call to Foswiki::Engine::finalize | ||
43 | } | ||||
44 | } | ||||
45 | |||||
46 | # spent 122µs (96+26) within Foswiki::Engine::CGI::prepareConnection which was called:
# once (96µs+26µs) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 94 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
47 | 6 | 40µs | my ( $this, $req ) = @_; | ||
48 | |||||
49 | 1 | 8µs | $req->remoteAddress( $ENV{REMOTE_ADDR} ); # spent 8µs making 1 call to Foswiki::Request::remoteAddress | ||
50 | 1 | 10µs | $req->method( $ENV{REQUEST_METHOD} ); # spent 10µs making 1 call to Foswiki::Request::method | ||
51 | |||||
52 | if ( $ENV{HTTPS} && uc( $ENV{HTTPS} ) eq 'ON' ) { | ||||
53 | $req->secure(1); | ||||
54 | } | ||||
55 | |||||
56 | if ( $ENV{SERVER_PORT} && $ENV{SERVER_PORT} == 443 ) { | ||||
57 | $req->secure(1); | ||||
58 | } | ||||
59 | 1 | 7µs | $req->serverPort( $ENV{SERVER_PORT} ); # spent 7µs making 1 call to Foswiki::Request::serverPort | ||
60 | } | ||||
61 | |||||
62 | # spent 8µs within Foswiki::Engine::CGI::prepareQueryParameters which was called:
# once (8µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 95 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
63 | 2 | 12µs | my ( $this, $req ) = @_; | ||
64 | $this->SUPER::prepareQueryParameters( $req, $ENV{QUERY_STRING} ) | ||||
65 | if $ENV{QUERY_STRING}; | ||||
66 | } | ||||
67 | |||||
68 | # spent 919µs (308+611) within Foswiki::Engine::CGI::prepareHeaders which was called:
# once (308µs+611µs) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 96 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
69 | 3 | 33µs | my ( $this, $req ) = @_; | ||
70 | foreach my $header ( keys %ENV ) { | ||||
71 | 47 | 361µs | 31 | 66µs | next unless $header =~ /^(?:HTTP|CONTENT|COOKIE)/i; # spent 66µs making 31 calls to Foswiki::Engine::CGI::CORE:match, avg 2µs/call |
72 | 8 | 28µs | ( my $field = $header ) =~ s/^HTTPS?_//; # spent 28µs making 8 calls to Foswiki::Engine::CGI::CORE:subst, avg 4µs/call | ||
73 | 8 | 509µs | $req->header( $field => $ENV{$header} ); # spent 509µs making 8 calls to Foswiki::Request::header, avg 64µs/call | ||
74 | } | ||||
75 | 1 | 7µs | $req->remoteUser( $ENV{REMOTE_USER} ); # spent 7µs making 1 call to Foswiki::Request::remoteUser | ||
76 | } | ||||
77 | |||||
78 | # spent 195µs (107+88) within Foswiki::Engine::CGI::preparePath which was called:
# once (107µs+88µs) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 98 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
79 | 14 | 148µs | my ( $this, $req ) = @_; | ||
80 | |||||
81 | # SMELL: "The Microsoft Internet Information Server is broken with | ||||
82 | # respect to additional path information. If you use the Perl DLL | ||||
83 | # library, the IIS server will attempt to execute the additional | ||||
84 | # path information as a Perl script. If you use the ordinary file | ||||
85 | # associations mapping, the path information will be present in the | ||||
86 | # environment, but incorrect. The best thing to do is to avoid using | ||||
87 | # additional path information." | ||||
88 | |||||
89 | # Clean up PATH_INFO problems, e.g. Support.CobaltRaqInstall. A valid | ||||
90 | # PATH_INFO is '/Main/WebHome', i.e. the text after the script name; | ||||
91 | # invalid PATH_INFO is often a full path starting with '/cgi-bin/...'. | ||||
92 | my $pathInfo = $ENV{PATH_INFO} || ''; | ||||
93 | unless ( defined $ENV{SCRIPT_NAME} ) { | ||||
94 | |||||
95 | # CGI/1.1 (rfc3875) states that the server MUST set | ||||
96 | # SCRIPT_NAME, so if it doens't we have a broken server | ||||
97 | my $reason = 'SCRIPT_NAME environment variable not defined'; | ||||
98 | my $res = new Foswiki::Response(); | ||||
99 | $res->header( -type => 'text/html', -status => 500 ); | ||||
100 | my $html = CGI::start_html('500 - Internal Server Error'); | ||||
101 | $html .= CGI::h1( {}, 'Internal Server Error' ); | ||||
102 | $html .= CGI::p( {}, $reason ); | ||||
103 | $html .= CGI::end_html(); | ||||
104 | $res->print($html); | ||||
105 | throw Foswiki::EngineException( 500, $reason, $res ); | ||||
106 | } | ||||
107 | my $cgiScriptPath = $ENV{SCRIPT_NAME}; | ||||
108 | 2 | 26µs | $pathInfo =~ s{^$cgiScriptPath(?:/+|$)}{/}; # spent 24µs making 1 call to Foswiki::Engine::CGI::CORE:regcomp
# spent 2µs making 1 call to Foswiki::Engine::CGI::CORE:subst | ||
109 | my $cgiScriptName = $cgiScriptPath; | ||||
110 | 3 | 25µs | $cgiScriptName =~ s/.*?(\w+)(\.\w+)?$/$1/; # spent 19µs making 1 call to Foswiki::Engine::CGI::CORE:subst
# spent 7µs making 2 calls to Foswiki::Engine::CGI::CORE:substcont, avg 3µs/call | ||
111 | |||||
112 | my $action; | ||||
113 | 1 | 3µs | if ( exists $ENV{FOSWIKI_ACTION} ) { | ||
114 | |||||
115 | # This handles scripts that have set $FOSWIKI_ACTION | ||||
116 | $action = $ENV{FOSWIKI_ACTION}; | ||||
117 | } | ||||
118 | elsif ( exists $Foswiki::cfg{SwitchBoard}{$cgiScriptName} ) { | ||||
119 | |||||
120 | # This handles other named CGI scripts that have a switchboard entry | ||||
121 | # but haven't set $FOSWIKI_ACTION (old-style run scripts) | ||||
122 | $action = $cgiScriptName; | ||||
123 | } | ||||
124 | elsif ( length $pathInfo > 1 ) { | ||||
125 | |||||
126 | # This handles twiki_cgi; use the first path el after the script | ||||
127 | # name as the function | ||||
128 | $pathInfo =~ m{^/([^/]+)(.*)}; | ||||
129 | my $first = $1; # implicit untaint OK; checked below | ||||
130 | if ( exists $Foswiki::cfg{SwitchBoard}{$first} ) { | ||||
131 | |||||
132 | # The path is of the form script/function/... | ||||
133 | $action = $first; | ||||
134 | $pathInfo = $2 || ''; | ||||
135 | } | ||||
136 | } | ||||
137 | $action ||= 'view'; | ||||
138 | 1 | 5µs | ASSERT( defined $pathInfo ) if DEBUG; # spent 5µs making 1 call to Assert::ASSERTS_OFF | ||
139 | 1 | 17µs | $req->action($action); # spent 17µs making 1 call to Foswiki::Request::action | ||
140 | 1 | 8µs | $req->pathInfo($pathInfo); # spent 8µs making 1 call to Foswiki::Request::pathInfo | ||
141 | 1 | 8µs | $req->uri( $ENV{REQUEST_URI} # spent 8µs making 1 call to Foswiki::Request::uri | ||
142 | || $req->url( -absolute => 1, -path => 1, -query => 1 ) ); | ||||
143 | } | ||||
144 | |||||
145 | # spent 8µs within Foswiki::Engine::CGI::prepareBody which was called:
# once (8µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 99 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
146 | 2 | 11µs | my ( $this, $req ) = @_; | ||
147 | |||||
148 | return unless $ENV{CONTENT_LENGTH}; | ||||
149 | my $cgi = new CGI(); | ||||
150 | my $err = $cgi->cgi_error; | ||||
151 | throw Foswiki::EngineException( $1, $2 ) | ||||
152 | if defined $err && $err =~ /\s*(\d{3})\s*(.*)/; | ||||
153 | $this->{cgi} = $cgi; | ||||
154 | } | ||||
155 | |||||
156 | # spent 7µs within Foswiki::Engine::CGI::prepareBodyParameters which was called:
# once (7µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 100 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
157 | 2 | 10µs | my ( $this, $req ) = @_; | ||
158 | |||||
159 | return unless $ENV{CONTENT_LENGTH}; | ||||
160 | my @plist = $this->{cgi}->param(); | ||||
161 | foreach my $pname (@plist) { | ||||
162 | my @values = map { "$_" } $this->{cgi}->param($pname); | ||||
163 | $req->bodyParam( -name => $pname, -value => \@values ); | ||||
164 | $this->{uploads}{$pname} = 1 if scalar $this->{cgi}->upload($pname); | ||||
165 | } | ||||
166 | } | ||||
167 | |||||
168 | # spent 7µs within Foswiki::Engine::CGI::prepareUploads which was called:
# once (7µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 101 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
169 | 2 | 10µs | my ( $this, $req ) = @_; | ||
170 | |||||
171 | return unless $ENV{CONTENT_LENGTH}; | ||||
172 | my %uploads; | ||||
173 | foreach my $key ( keys %{ $this->{uploads} } ) { | ||||
174 | my $fname = $this->{cgi}->param($key); | ||||
175 | $uploads{"$fname"} = new Foswiki::Request::Upload( | ||||
176 | headers => $this->{cgi}->uploadInfo($fname), | ||||
177 | tmpname => $this->{cgi}->tmpFileName($fname), | ||||
178 | ); | ||||
179 | } | ||||
180 | delete $this->{uploads}; | ||||
181 | $req->uploads( \%uploads ); | ||||
182 | } | ||||
183 | |||||
184 | # spent 42µs (33+9) within Foswiki::Engine::CGI::finalizeUploads which was called:
# once (33µs+9µs) by Foswiki::Engine::finalize at line 299 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
185 | 3 | 22µs | my ( $this, $res, $req ) = @_; | ||
186 | |||||
187 | 1 | 10µs | 1 | 9µs | $req->delete($_) foreach keys %{ $req->uploads }; # spent 9µs making 1 call to Foswiki::Request::uploads |
188 | undef $this->{cgi}; | ||||
189 | } | ||||
190 | |||||
191 | # spent 1.70ms (67µs+1.63) within Foswiki::Engine::CGI::finalizeHeaders which was called:
# once (67µs+1.63ms) by Foswiki::Engine::finalize at line 300 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
192 | 4 | 482µs | my ( $this, $res, $req ) = @_; | ||
193 | 1 | 820µs | $this->SUPER::finalizeHeaders( $res, $req ); # spent 820µs making 1 call to Foswiki::Engine::finalizeHeaders | ||
194 | |||||
195 | 1 | 397µs | my $hdr = $res->printHeaders; # spent 397µs making 1 call to Foswiki::Response::printHeaders | ||
196 | 1 | 414µs | print $hdr; # spent 414µs making 1 call to Foswiki::Engine::CGI::CORE:print | ||
197 | } | ||||
198 | |||||
199 | # spent 72µs (35+37) within Foswiki::Engine::CGI::write which was called:
# once (35µs+37µs) by Foswiki::Engine::finalizeBody at line 409 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm | ||||
200 | 2 | 75µs | my ( $this, $buffer ) = @_; | ||
201 | 1 | 37µs | print $buffer; # spent 37µs making 1 call to Foswiki::Engine::CGI::CORE:print | ||
202 | } | ||||
203 | |||||
204 | 1 | 6µs | 1; | ||
205 | __END__ | ||||
# spent 66µs within Foswiki::Engine::CGI::CORE:match which was called 31 times, avg 2µs/call:
# 31 times (66µs+0s) by Foswiki::Engine::CGI::prepareHeaders at line 71, avg 2µs/call | |||||
sub Foswiki::Engine::CGI::CORE:print; # opcode | |||||
# spent 24µs within Foswiki::Engine::CGI::CORE:regcomp which was called:
# once (24µs+0s) by Foswiki::Engine::CGI::preparePath at line 108 | |||||
# spent 49µs within Foswiki::Engine::CGI::CORE:subst which was called 10 times, avg 5µs/call:
# 8 times (28µs+0s) by Foswiki::Engine::CGI::prepareHeaders at line 72, avg 4µs/call
# once (19µs+0s) by Foswiki::Engine::CGI::preparePath at line 110
# once (2µs+0s) by Foswiki::Engine::CGI::preparePath at line 108 | |||||
# spent 7µs within Foswiki::Engine::CGI::CORE:substcont which was called 2 times, avg 3µs/call:
# 2 times (7µs+0s) by Foswiki::Engine::CGI::preparePath at line 110, avg 3µs/call |