| 1 | package SockJS::Transport::HtmlFile; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base 'SockJS::Transport::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 5 | my $self = shift->SUPER::new(@_); | |||||||||||||||||||||||||||
| 10 | 5 | my (%params) = @_; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | $self->{response_limit} = $params{response_limit} || 128 * 1024; | ||||||||||||||||||||||||||
|
Condition50%1/2
$params{'response_limit'} || 131072
MC/DC0%0/1
$params{'response_limit'} || 131072
$params{'response_limit'}
Truth table50%1/2
A
A= $params{'response_limit'}
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | push @{$self->{allowed_methods}}, 'GET'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | return $self; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | sub dispatch_GET { | ||||||||||||||||||||||||||
|
Subroutine
dispatch_GET: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 5 | my ($env, $conn) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5 | my ($callback) = $env->{QUERY_STRING} =~ m/(?:^|&|;)c=([^&;]+)/; | |||||||||||||||||||||||||||
| 24 | 5 | ▶ | if (!$callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | return [500, [], ['"callback" parameter required']]; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | $callback =~ s/%(..)/chr(hex($1))/eg; | |||||||||||||||||||||||||||
| 29 | 4 | ▶ | if ($callback !~ m/^[a-zA-Z0-9-_\.]+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 1 | return [500, [], ['invalid "callback" parameter']]; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | my $limit = $self->{response_limit}; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 3 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||
| 36 | 3 | my $respond = shift; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 3 | my $writer = $respond->( | |||||||||||||||||||||||||||
| 39 | [ | ||||||||||||||||||||||||||||
| 40 | 200, | ||||||||||||||||||||||||||||
| 41 | [ | ||||||||||||||||||||||||||||
| 42 | 'Content-Type' => 'text/html; charset=UTF-8', | ||||||||||||||||||||||||||||
| 43 | 'Connection' => 'close', | ||||||||||||||||||||||||||||
| 44 | ] | ||||||||||||||||||||||||||||
| 45 | ] | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | ▶ | if ($conn->is_connected && !$conn->is_reconnecting) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$conn->is_connected and not $conn->is_reconnecting
MC/DC50%1/2
$conn->is_connected and not $conn->is_reconnecting
$conn->is_connected
not $conn->is_reconnecting
Truth table66%2/3
A and not(B)
A= $conn->is_connectedB= not $conn->is_reconnecting
| |||||||||||||||||||||||||||||
| 49 | 1 | my $message = $self->_wrap_message( | |||||||||||||||||||||||||||
| 50 | 'c[2010,"Another connection still open"]' . "\n"); | ||||||||||||||||||||||||||||
| 51 | 1 | $writer->write($message); | |||||||||||||||||||||||||||
| 52 | 1 | $writer->close; | |||||||||||||||||||||||||||
| 53 | 1 | return; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | $conn->write_cb( | ||||||||||||||||||||||||||||
| 57 | 2 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 58 | 2 | my $conn = shift; | |||||||||||||||||||||||||||
| 59 | 2 | my ($message) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | $limit -= length($message) - 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | $writer->write($self->_wrap_message($message)); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | if ($limit <= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | $writer->close; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | $conn->reconnecting; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 2 | ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $conn->close_cb(sub { $writer->close }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | $writer->write(<<"EOF" . (' ' x 1024)); | |||||||||||||||||||||||||||
| 76 | <!doctype html> | ||||||||||||||||||||||||||||
| 77 | <html><head> | ||||||||||||||||||||||||||||
| 78 | <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||||||||||||||||||||||||||||
| 79 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||||||||||||||||||||||||||
| 80 | </head><body><h2>Don't panic!</h2> | ||||||||||||||||||||||||||||
| 81 | <script> | ||||||||||||||||||||||||||||
| 82 | document.domain = document.domain; | ||||||||||||||||||||||||||||
| 83 | var c = parent.callback; | ||||||||||||||||||||||||||||
| 84 | c.start(); | ||||||||||||||||||||||||||||
| 85 | function p(d) {c.message(d);}; | ||||||||||||||||||||||||||||
| 86 | window.onload = function() {c.stop();}; | ||||||||||||||||||||||||||||
| 87 | </script> | ||||||||||||||||||||||||||||
| 88 | EOF | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | $conn->write('o'); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | ▶ | if ($conn->is_closed) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 93 | 0 | $conn->connected; | |||||||||||||||||||||||||||
| 94 | 0 | $conn->close; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | elsif ($conn->is_connected) { | ||||||||||||||||||||||||||||
| 97 | 0 | $conn->reconnected; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||
| 100 | 2 | $conn->connected; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 3 | }; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | sub _wrap_message { | ||||||||||||||||||||||||||
|
Subroutine
_wrap_message: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | 3 | my ($message) = @_; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 3 | $message =~ s/(['""\\\/\n\r\t]{1})/\\$1/smg; | |||||||||||||||||||||||||||
| 110 | 3 | return qq{<script>\np("$message");\n</script>\r\n}; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | 1; | |||||||||||||||||||||||||||