line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PAB3::CGI; |
2
|
|
|
|
|
|
|
# ============================================================================= |
3
|
|
|
|
|
|
|
# Perl Application Builder |
4
|
|
|
|
|
|
|
# Module: PAB3::CGI::RequestStd |
5
|
|
|
|
|
|
|
# Use "perldoc PAB3::CGI" for documenation |
6
|
|
|
|
|
|
|
# ============================================================================= |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _create_param { |
11
|
4
|
|
|
4
|
|
7
|
my( $key, $val, $post ) = @_; |
12
|
4
|
|
|
|
|
4
|
my( $len ); |
13
|
4
|
|
|
|
|
7
|
$len = length( $key ); |
14
|
4
|
100
|
|
|
|
13
|
if( substr( $key, $len - 2, 2 ) eq '[]' ) { |
15
|
2
|
|
|
|
|
3
|
$key = substr( $key, 0, $len - 2 ); |
16
|
2
|
50
|
|
|
|
5
|
if( $post ) { |
17
|
0
|
0
|
|
|
|
0
|
$_POST{$key} = [] if ref( $_POST{$key} ) ne 'ARRAY'; |
18
|
0
|
|
|
|
|
0
|
push @{$_POST{$key}}, $val; |
|
0
|
|
|
|
|
0
|
|
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
2
|
100
|
|
|
|
9
|
$_GET{$key} = [] if ref( $_GET{$key} ) ne 'ARRAY'; |
22
|
2
|
|
|
|
|
2
|
push @{$_GET{$key}}, $val; |
|
2
|
|
|
|
|
5
|
|
23
|
|
|
|
|
|
|
} |
24
|
2
|
100
|
|
|
|
7
|
$_REQUEST{$key} = [] if ref( $_REQUEST{$key} ) ne 'ARRAY'; |
25
|
2
|
|
|
|
|
3
|
push @{$_REQUEST{$key}}, $val; |
|
2
|
|
|
|
|
6
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
2
|
50
|
|
|
|
4
|
if( $post ) { |
29
|
0
|
0
|
|
|
|
0
|
$_POST{$key} .= defined $_POST{$key} ? "\0" . $val : $val; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
2
|
50
|
|
|
|
13
|
$_GET{$key} .= defined $_GET{$key} ? "\0" . $val : $val; |
33
|
|
|
|
|
|
|
} |
34
|
2
|
50
|
|
|
|
10
|
$_REQUEST{$key} .= defined $_REQUEST{$key} ? "\0" . $val : $val; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _parse_request { |
39
|
2
|
|
|
2
|
|
287
|
my( $len, $meth, $got, $input, $post, $jmp ); |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
6
|
%_GET = (); |
42
|
2
|
|
|
|
|
25
|
%_POST = (); |
43
|
2
|
|
|
|
|
5
|
%_REQUEST = (); |
44
|
2
|
|
|
|
|
4
|
%_FILES = (); |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
7
|
binmode( STDIN ); |
47
|
2
|
|
|
|
|
890
|
binmode( STDOUT ); |
48
|
2
|
|
|
|
|
6
|
binmode( STDERR ); |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
5
|
$len = $ENV{'CONTENT_LENGTH'}; |
51
|
2
|
|
|
|
|
5
|
$meth = $ENV{'REQUEST_METHOD'}; |
52
|
|
|
|
|
|
|
|
53
|
2
|
0
|
33
|
|
|
8
|
if( $len && $RequestMaxData && $len > $RequestMaxData ) { |
|
|
|
0
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
&Carp::croak( |
55
|
|
|
|
|
|
|
"CGI Error: Request to receive too much data: $len bytes" |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
3
|
my( @tb, $i, $iv, $key, $val ); |
60
|
2
|
|
|
|
|
4
|
@tb = (); |
61
|
2
|
50
|
|
|
|
7
|
if( ! $meth ) { |
62
|
0
|
|
|
|
|
0
|
push @tb, @ARGV; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
2
|
|
50
|
|
|
15
|
push @tb, split( /[&;]/, $ENV{'QUERY_STRING'} || '' ); |
66
|
2
|
50
|
|
|
|
6
|
if( $meth eq 'POST' ) { |
67
|
0
|
|
|
|
|
0
|
$jmp = 'parse_post'; |
68
|
0
|
|
|
|
|
0
|
goto parse_std; |
69
|
0
|
|
|
|
|
0
|
parse_post: |
70
|
|
|
|
|
|
|
$jmp = undef; |
71
|
0
|
|
|
|
|
0
|
$post = 1; |
72
|
0
|
|
|
|
|
0
|
read( STDIN, $input, $len ); |
73
|
0
|
|
|
|
|
0
|
push @tb, split( /[&;]/, $input ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
parse_std: |
77
|
2
|
|
|
|
|
7
|
for $i( 0 .. $#tb ) { |
78
|
4
|
|
|
|
|
8
|
$iv = index( $tb[$i], '=' ); |
79
|
4
|
50
|
|
|
|
11
|
if( $iv > 0 ) { |
80
|
4
|
|
|
|
|
8
|
$key = substr( $tb[$i], 0, $iv ); |
81
|
4
|
|
|
|
|
7
|
$val = substr( $tb[$i], $iv + 1 ); |
82
|
4
|
|
|
|
|
7
|
$key =~ tr/+/ /; |
83
|
4
|
|
|
|
|
5
|
$key =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge; |
|
0
|
|
|
|
|
0
|
|
84
|
4
|
50
|
|
|
|
10
|
if( $val ) { |
85
|
4
|
|
|
|
|
6
|
$val =~ tr/+/ /; |
86
|
4
|
|
|
|
|
11
|
$val =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge; |
|
1
|
|
|
|
|
7
|
|
87
|
|
|
|
|
|
|
} |
88
|
4
|
50
|
|
|
|
7
|
if( $post ) { |
89
|
0
|
|
|
|
|
0
|
&_create_param( $key, $val, 1 ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
4
|
|
|
|
|
9
|
&_create_param( $key, $val, 0 ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
0
|
|
|
|
|
0
|
$tb[$i] =~ tr/+/ /; |
97
|
0
|
|
|
|
|
0
|
$tb[$i] =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge; |
|
0
|
|
|
|
|
0
|
|
98
|
0
|
0
|
|
|
|
0
|
if( $post ) { |
99
|
0
|
|
|
|
|
0
|
&_create_param( $tb[$i], '', 1 ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
0
|
|
|
|
|
0
|
&_create_param( $tb[$i], '', 0 ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
2
|
50
|
|
|
|
5
|
goto $jmp if $jmp; |
107
|
2
|
|
|
|
|
8
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |