line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Filter::SimpleHTTP::Regex; |
2
|
|
|
|
|
|
|
our $VERSION = '0.091710'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
6119
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
149
|
|
6
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1588
|
use bytes; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
13
|
|
9
|
2
|
|
|
2
|
|
4150
|
use Regexp::Common('URI'); |
|
2
|
|
|
|
|
7445
|
|
|
2
|
|
|
|
|
10
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub quote_it |
12
|
|
|
|
|
|
|
{ |
13
|
6
|
|
|
6
|
0
|
321
|
$_[0] =~ s/([^[:alnum:][:cntrl:][:space:]])/\\$1/g; |
14
|
|
|
|
|
|
|
|
15
|
6
|
100
|
|
|
|
30
|
if($_[0] =~ /-/) |
16
|
|
|
|
|
|
|
{ |
17
|
4
|
|
|
|
|
18
|
$_[0] =~ s/-//g; |
18
|
4
|
|
|
|
|
9
|
$_[0] .= '-'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
|
|
20
|
return $_[0]; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub gen_char |
25
|
|
|
|
|
|
|
{ |
26
|
2
|
|
|
2
|
0
|
8
|
return '[' . quote_it( join('', map { chr($_) } 0..127) ) . ']'; |
|
256
|
|
|
|
|
615
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub exclude |
30
|
|
|
|
|
|
|
{ |
31
|
10
|
|
|
10
|
0
|
21
|
my ($pattern, $fromwhat) = @_; |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
21
|
$fromwhat = substr($fromwhat, 1, length($fromwhat) - 2); |
34
|
|
|
|
|
|
|
|
35
|
10
|
|
|
|
|
348
|
$fromwhat =~ s/$pattern//g; |
36
|
|
|
|
|
|
|
|
37
|
10
|
|
|
|
|
48
|
return "[$fromwhat]"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub gen_ctrl |
41
|
|
|
|
|
|
|
{ |
42
|
2
|
|
|
2
|
0
|
5
|
return '[' . quote_it( join '', map { chr($_) } (0..31, 127) ) . ']'; |
|
66
|
|
|
|
|
97
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub gen_octet |
46
|
|
|
|
|
|
|
{ |
47
|
2
|
|
|
2
|
0
|
8
|
return '[' . quote_it( join('', map { chr($_) } 0..255) ) . ']'; |
|
512
|
|
|
|
|
2018
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub gen_separators |
51
|
|
|
|
|
|
|
{ |
52
|
34
|
|
|
|
|
55
|
return join |
53
|
|
|
|
|
|
|
( |
54
|
|
|
|
|
|
|
'|', |
55
|
|
|
|
|
|
|
( |
56
|
2
|
|
|
2
|
0
|
22
|
map { chr(92).$_ } |
57
|
|
|
|
|
|
|
( |
58
|
|
|
|
|
|
|
split |
59
|
|
|
|
|
|
|
( |
60
|
|
|
|
|
|
|
/\s/, |
61
|
|
|
|
|
|
|
'( ) < > @ , ; : \ " / [ ] ? = { }'.' '.chr(32).' '.chr(9) |
62
|
|
|
|
|
|
|
) |
63
|
|
|
|
|
|
|
) |
64
|
|
|
|
|
|
|
) |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $oct = gen_octet(); |
69
|
|
|
|
|
|
|
my $char = gen_char(); |
70
|
|
|
|
|
|
|
my $upalpha = '[A-Z]'; |
71
|
|
|
|
|
|
|
my $loalpha = '[a-z]'; |
72
|
|
|
|
|
|
|
my $mark = q|[_.!~*'()-]|; |
73
|
|
|
|
|
|
|
my $digit = '[0-9]'; |
74
|
|
|
|
|
|
|
my $hex = "[a-fA-F]|$digit]"; |
75
|
|
|
|
|
|
|
my $alpha = "(?:$upalpha|$loalpha)"; |
76
|
|
|
|
|
|
|
my $alphanum = "(?:$alpha|$digit)"; |
77
|
|
|
|
|
|
|
my $unreserved = "(?:$alphanum|$mark)"; |
78
|
|
|
|
|
|
|
my $escaped = "(?:%$hex+)"; |
79
|
|
|
|
|
|
|
my $pchar = "(?:$unreserved|$escaped|".'[:@&=+$,])'; |
80
|
|
|
|
|
|
|
my $segment = "(?:$pchar*(?:;$pchar)*)"; |
81
|
|
|
|
|
|
|
my $path_segs = "(?:$segment(?:/$segment)*)"; |
82
|
|
|
|
|
|
|
my $abs_path = "(?:/$path_segs)"; |
83
|
|
|
|
|
|
|
my $ctrl = gen_ctrl(); |
84
|
|
|
|
|
|
|
my $cr = chr(13); |
85
|
|
|
|
|
|
|
my $lf = chr(10); |
86
|
|
|
|
|
|
|
my $sp = chr(32); |
87
|
|
|
|
|
|
|
my $ht = chr(9); |
88
|
|
|
|
|
|
|
my $dq = chr(34); |
89
|
|
|
|
|
|
|
my $crlf = "(?:$cr$lf)"; |
90
|
|
|
|
|
|
|
my $lws = "(?:$crlf*(?:$sp|$ht)+)"; |
91
|
|
|
|
|
|
|
my $text = exclude($ctrl,$oct); |
92
|
|
|
|
|
|
|
my $separators = gen_separators(); |
93
|
|
|
|
|
|
|
my $token = exclude( $ctrl, exclude( $separators, $char ) ); |
94
|
|
|
|
|
|
|
my $ctext = exclude( "[()]", $text ); |
95
|
|
|
|
|
|
|
my $quot_pair = "\\$char"; |
96
|
|
|
|
|
|
|
my $comment = "(?:\((?:$ctext|$quot_pair|\1)*\))"; |
97
|
|
|
|
|
|
|
my $qdtext = exclude( q/"/, $text ); |
98
|
|
|
|
|
|
|
my $quot_str = "(?:\"(?:$qdtext|$quot_pair)*\")"; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $httpvers = "HTTP\/$digit+\.$digit+"; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $f_content = "$text|$token|$separators|$quot_str"; |
103
|
|
|
|
|
|
|
my $f_value = "(?:(?:$f_content+)|$lws)"; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $header = "($token+):($f_value*)"; |
106
|
|
|
|
|
|
|
my $method = "OPTIONS|GET|HEAD|POST|PUT|DELETE|CONNECT|$token"; |
107
|
|
|
|
|
|
|
my $req_line = "($method)$sp(" . $RE{'URI'}{'HTTP'}.'|'. $abs_path. ")$sp($httpvers)$crlf*"; |
108
|
|
|
|
|
|
|
my $resp_code = $digit . '{3}'; |
109
|
|
|
|
|
|
|
my $resp_line = "($httpvers)$sp($resp_code)$sp($text)*$crlf*"; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
our $RESPONSE = qr/$resp_line/; |
112
|
|
|
|
|
|
|
our $REQUEST = qr/$req_line/; |
113
|
|
|
|
|
|
|
our $HEADER = qr/$header/; |
114
|
|
|
|
|
|
|
our $PROTOCOL = qr/$httpvers/; |
115
|
|
|
|
|
|
|
our $METHOD = qr/$method/; |
116
|
|
|
|
|
|
|
our $URI = qr/$RE{'URI'}{'HTTP'}|$abs_path/; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#my $HTTP = 'HTTP/1.1'; |
119
|
|
|
|
|
|
|
#my $CODE = '200'; |
120
|
|
|
|
|
|
|
#my $MESSAGE = 'OK'; |
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
#if($HTTP =~ /(?:$httpvers)/) |
123
|
|
|
|
|
|
|
#{ |
124
|
|
|
|
|
|
|
# warn 'PASSED HTTP'; |
125
|
|
|
|
|
|
|
#} |
126
|
|
|
|
|
|
|
# |
127
|
|
|
|
|
|
|
#if($CODE =~ /(?:$resp_code)/) |
128
|
|
|
|
|
|
|
#{ |
129
|
|
|
|
|
|
|
# warn 'PASSED RESPONSE CODE'; |
130
|
|
|
|
|
|
|
#} |
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
#if($MESSAGE =~ /(?:$text)/) |
133
|
|
|
|
|
|
|
#{ |
134
|
|
|
|
|
|
|
# warn 'PASSED MESSAGE TEXT'; |
135
|
|
|
|
|
|
|
#} |
136
|
|
|
|
|
|
|
# |
137
|
|
|
|
|
|
|
#my $COMBINED = "$HTTP $CODE $MESSAGE\x0D\x0A"; |
138
|
|
|
|
|
|
|
# |
139
|
|
|
|
|
|
|
#if($COMBINED =~ /(?:$httpvers)$sp(?:$resp_code)$sp(?:$text)*$crlf/) |
140
|
|
|
|
|
|
|
#{ |
141
|
|
|
|
|
|
|
# warn 'PASSED RESPONSE LINE'; |
142
|
|
|
|
|
|
|
#} |
143
|
|
|
|
|
|
|
# |
144
|
|
|
|
|
|
|
#my $HEAD1 = "Server: Apache/1.3.37 (Unix) mod_perl/1.29"; |
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
#if($HEAD1 =~ /(?:$token):(?:$f_value)*/) |
147
|
|
|
|
|
|
|
#{ |
148
|
|
|
|
|
|
|
# warn 'PASSED HEADER 1 '; |
149
|
|
|
|
|
|
|
#} |
150
|
|
|
|
|
|
|
# |
151
|
|
|
|
|
|
|
#my $HEAD2 = "Date: Sun, 05 Aug 2007 18:46:50 GMT"; |
152
|
|
|
|
|
|
|
# |
153
|
|
|
|
|
|
|
#if($HEAD2 =~ $POE::Filter::SimpleHTTP::Regex::HEADER) |
154
|
|
|
|
|
|
|
#{ |
155
|
|
|
|
|
|
|
# warn 'PASSED HEADER2'; |
156
|
|
|
|
|
|
|
# warn $1; |
157
|
|
|
|
|
|
|
# warn $2; |
158
|
|
|
|
|
|
|
#} |
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
#my $COMB_REQ = "GET / $HTTP"; |
161
|
|
|
|
|
|
|
# |
162
|
|
|
|
|
|
|
#if($COMB_REQ =~ $POE::Filter::SimpleHTTP::Regex::REQUEST) |
163
|
|
|
|
|
|
|
#{ |
164
|
|
|
|
|
|
|
# warn 'PASSED REQUEST'; |
165
|
|
|
|
|
|
|
#} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
#warn $POE::Filter::SimpleHTTP::Regex::REQUEST; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#$string =~ s/[[:cntrl:]]//g; |
170
|
|
|
|
|
|
|
#$string =~ s/(?<!\\)(\()(?!\?:)/\n$1\n/g; |
171
|
|
|
|
|
|
|
#$string =~ s/(?<!\\)(\()(?=\?:)/\n\t$1/g; |
172
|
|
|
|
|
|
|
#$string =~ s/(?<!\\)(\))/\n$1\n/g; |
173
|
|
|
|
|
|
|
#$string =~ s/$crlf//g; |
174
|
|
|
|
|
|
|
#$string =~ s/$lws//g; |
175
|
|
|
|
|
|
|
#warn $string; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |