| 1 | package POE::Filter::SimpleHTTP::Regex; | ||||||||||
| 2 | 3 | our $VERSION = '0.091710'; | |||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use bytes; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use Regexp::Common('URI'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | sub quote_it | ||||||||||
| 12 | 9 | ▶ | { | ||||||||
|
Subroutine
quote_it: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 13 | 9 | $_[0] =~ s/([^[:alnum:][:cntrl:][:space:]])/\\$1/g; | |||||||||
| 14 | |||||||||||
| 15 | 9 | ▶ | if($_[0] =~ /-/) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | { | ||||||||||
| 17 | 6 | $_[0] =~ s/-//g; | |||||||||
| 18 | 6 | $_[0] .= '-'; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 9 | return $_[0]; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub gen_char | ||||||||||
| 25 | 3 | ▶ | { | ||||||||
|
Subroutine
gen_char: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 26 | 3 | return '[' . quote_it( join('', map { chr($_) } 0..127) ) . ']'; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | sub exclude | ||||||||||
| 30 | 15 | ▶ | { | ||||||||
|
Subroutine
exclude: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 31 | 15 | my ($pattern, $fromwhat) = @_; | |||||||||
| 32 | |||||||||||
| 33 | 15 | $fromwhat = substr($fromwhat, 1, length($fromwhat) - 2); | |||||||||
| 34 | |||||||||||
| 35 | 15 | $fromwhat =~ s/$pattern//g; | |||||||||
| 36 | |||||||||||
| 37 | 15 | return "[$fromwhat]"; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub gen_ctrl | ||||||||||
| 41 | 3 | ▶ | { | ||||||||
|
Subroutine
gen_ctrl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | 3 | return '[' . quote_it( join '', map { chr($_) } (0..31, 127) ) . ']'; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub gen_octet | ||||||||||
| 46 | 3 | ▶ | { | ||||||||
|
Subroutine
gen_octet: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 47 | 3 | return '[' . quote_it( join('', map { chr($_) } 0..255) ) . ']'; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub gen_separators | ||||||||||
| 51 | 3 | ▶ | { | ||||||||
|
Subroutine
gen_separators: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 52 | return join | ||||||||||
| 53 | ( | ||||||||||
| 54 | '|', | ||||||||||
| 55 | ( | ||||||||||
| 56 | 3 | map { chr(92).$_ } | |||||||||
| 57 | ( | ||||||||||
| 58 | split | ||||||||||
| 59 | ( | ||||||||||
| 60 | /\s/, | ||||||||||
| 61 | '( ) < > @ , ; : \ " / [ ] ? = { }'.' '.chr(32).' '.chr(9) | ||||||||||
| 62 | ) | ||||||||||
| 63 | ) | ||||||||||
| 64 | ) | ||||||||||
| 65 | ); | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 3 | my $oct = gen_octet(); | |||||||||
| 69 | 3 | my $char = gen_char(); | |||||||||
| 70 | 3 | my $upalpha = '[A-Z]'; | |||||||||
| 71 | 3 | my $loalpha = '[a-z]'; | |||||||||
| 72 | 3 | my $mark = q|[_.!~*'()-]|; | |||||||||
| 73 | 3 | my $digit = '[0-9]'; | |||||||||
| 74 | 3 | my $hex = "[a-fA-F]|$digit]"; | |||||||||
| 75 | 3 | my $alpha = "(?:$upalpha|$loalpha)"; | |||||||||
| 76 | 3 | my $alphanum = "(?:$alpha|$digit)"; | |||||||||
| 77 | 3 | my $unreserved = "(?:$alphanum|$mark)"; | |||||||||
| 78 | 3 | my $escaped = "(?:%$hex+)"; | |||||||||
| 79 | 3 | my $pchar = "(?:$unreserved|$escaped|".'[:@&=+$,])'; | |||||||||
| 80 | 3 | my $segment = "(?:$pchar*(?:;$pchar)*)"; | |||||||||
| 81 | 3 | my $path_segs = "(?:$segment(?:/$segment)*)"; | |||||||||
| 82 | 3 | my $abs_path = "(?:/$path_segs)"; | |||||||||
| 83 | 3 | my $ctrl = gen_ctrl(); | |||||||||
| 84 | 3 | my $cr = chr(13); | |||||||||
| 85 | 3 | my $lf = chr(10); | |||||||||
| 86 | 3 | my $sp = chr(32); | |||||||||
| 87 | 3 | my $ht = chr(9); | |||||||||
| 88 | 3 | my $dq = chr(34); | |||||||||
| 89 | 3 | my $crlf = "(?:$cr$lf)"; | |||||||||
| 90 | 3 | my $lws = "(?:$crlf*(?:$sp|$ht)+)"; | |||||||||
| 91 | 3 | my $text = exclude($ctrl,$oct); | |||||||||
| 92 | 3 | my $separators = gen_separators(); | |||||||||
| 93 | 3 | my $token = exclude( $ctrl, exclude( $separators, $char ) ); | |||||||||
| 94 | 3 | my $ctext = exclude( "[()]", $text ); | |||||||||
| 95 | 3 | my $quot_pair = "\\$char"; | |||||||||
| 96 | 3 | my $comment = "(?:\((?:$ctext|$quot_pair|\1)*\))"; | |||||||||
| 97 | 3 | my $qdtext = exclude( q/"/, $text ); | |||||||||
| 98 | 3 | my $quot_str = "(?:\"(?:$qdtext|$quot_pair)*\")"; | |||||||||
| 99 | |||||||||||
| 100 | 3 | my $httpvers = "HTTP\/$digit+\.$digit+"; | |||||||||
| 101 | |||||||||||
| 102 | 3 | my $f_content = "$text|$token|$separators|$quot_str"; | |||||||||
| 103 | 3 | my $f_value = "(?:(?:$f_content+)|$lws)"; | |||||||||
| 104 | |||||||||||
| 105 | 3 | my $header = "($token+):($f_value*)"; | |||||||||
| 106 | 3 | my $method = "OPTIONS|GET|HEAD|POST|PUT|DELETE|CONNECT|$token"; | |||||||||
| 107 | 3 | my $req_line = "($method)$sp(" . $RE{'URI'}{'HTTP'}.'|'. $abs_path. ")$sp($httpvers)$crlf*"; | |||||||||
| 108 | 3 | my $resp_code = $digit . '{3}'; | |||||||||
| 109 | 3 | my $resp_line = "($httpvers)$sp($resp_code)$sp($text)*$crlf*"; | |||||||||
| 110 | |||||||||||
| 111 | 3 | our $RESPONSE = qr/$resp_line/; | |||||||||
| 112 | 3 | our $REQUEST = qr/$req_line/; | |||||||||
| 113 | 3 | our $HEADER = qr/$header/; | |||||||||
| 114 | 3 | our $PROTOCOL = qr/$httpvers/; | |||||||||
| 115 | 3 | our $METHOD = qr/$method/; | |||||||||
| 116 | 3 | 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 | 3 | 1; | |||||||||