SFLAP.pm

filter: Statementstmt 12.8% 16 / 125 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 16.6% 3 / 18 Podpod 0.0% 0 / 13 totaltotal 10.2% 19 / 185 CC 17 SCAR 22.1
CC
17
Cov
11%
new
20.0
clear_callbacks
12.0
debug
12.0
CRAP 9.1
« TOC.pm ↑ Summary
1 package AOL::SFLAP;
2  
3 1 ▶use IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 $VERSION = "0.33";
8  
9 1 $SFLAP_SIGNON = 1;
10 1 $SFLAP_DATA = 2;
11 1 $SFLAP_ERROR = 3;
12 1 $SFLAP_SIGNOFF = 4;
13 1 $SFLAP_KEEPALIVE = 5;
14  
15 0 ▶sub register_callback {
Subroutine register_callback: not called CC=1 SCAR=6.9
Pod undocumented
16 0 my ($self, $chan, $func, @args) = @_;
17  
18 #print "register_callback() func $func for chan $chan adding to $self->{callback}{$chan}\n";
19 #print " self $self selfcb = $self->{callback}\n";
20  
21 0 push (@{$self->{callback}{$chan}}, $func);
22 0 @{$self->{callback}{$func}} = @args;
23  
24 0 return;
25 }
26  
27 0 ▶sub clear_callbacks {
Subroutine clear_callbacks: not called CC=3 SCAR=24.8
Pod undocumented
28 0 my ($self) = @_;
29 0 my $k;
30  
31 0 print "...............C SFLAP clear_callbacks\n";
32 0 for $k (keys %{$self->{callback}}) {
33 0 print ".............C Clear key ($k)\n";
34 0 delete $self->{callback}{$k};
35 }
36  
37 0 print "...............S SFLAP scan callbacks\n";
38 0 for $k (keys %{$self->{callback}}) {
39 0 print ".............S Scan key ($k)\n";
40 }
41  
42 }
43  
44 0 ▶sub callback {
Subroutine callback: not called CC=2 SCAR=17.9
Pod undocumented
45 0 my ($self, $chan, @args) = @_;
46 0 my $func;
47  
48 0 for $func (@{$self->{callback}{$chan}}) {
49 #print ("callback() calling a func $func for $chan fd $self->{fd}..\n");
50 0 eval { &{$func} ($self, @args, @{$self->{callback}{$func}}) };
51 }
52  
53 0 return;
54 }
55  
56 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
57 0 my ($tochost, $authorizer, $port, $nickname) = @_;
58 0 my $self;
59 my $ipaddr;
60  
61 0 ▶ if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
Branch: 1 branch
BranchTrueFalseTotal
if ($port =~ /\D/) 0 0 0
62 0 ▶ die "invalid port" unless $port;
Branch: 1 branch
BranchTrueFalseTotal
unless $port 0 0 0
63  
64 0 $ipaddr = inet_aton($tochost);
65 0 ▶ die "unknown host" unless $ipaddr;
Branch: 1 branch
BranchTrueFalseTotal
unless $ipaddr 0 0 0
66  
67 0 $self = {
68 tochost => $tochost,
69 authorizer => $authorizer,
70 ipaddr => $ipaddr,
71 port => $port,
72 nickname => $nickname,
73 sequence => 1
74 };
75 0 bless($self);
76  
77 0 return $self;
78 }
79  
80 0 ▶sub destroy {
Subroutine destroy: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my ($self) = @_;
82  
83 0 print "sflap destroy\n";
84 0 CORE::close($self->{fd});
85  
86 0 $self = undef;
87  
88 0 return;
89 }
90  
91 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my ($self) = @_;
93 0 my $k;
94  
95 0 print "sflap close\n";
96  
97 0 $self->clear_callbacks();
98  
99 #CORE::close($self->{fd});
100  
101 0 return;
102 }
103  
104 0 ▶sub set_debug {
Subroutine set_debug: not called CC=1 SCAR=6.9
Pod undocumented
105 0 my ($self, $level) = @_;
106  
107 0 $self->{debug_level} = $level;
108 0 print "slfap debug level $level\n";
109 }
110  
111 0 ▶sub debug {
Subroutine debug: not called CC=3 SCAR=24.8
Pod undocumented
112 0 my ($self, @args) = @_;
113  
114 0 ▶ if (exists $self->{debug_level} && $self->{debug_level} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"debug_level"} and $self->{"debug_level"} > 0) 0 0 0
Condition0%0/3
exists $self->{"debug_level"} and $self->{"debug_level"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"debug_level"} and $self->{"debug_level"} > 0
exists $self->{"debug_level"} $self->{"debug_level"} > 0
Truth table0%0/3
A and B
A= exists $self->{"debug_level"}B= $self->{"debug_level"} > 0
ABresult
0X0
100
111
115 0 print @args;
116 }
117 }
118  
119 0 ▶sub __connect {
Subroutine __connect: not called CC=3 SCAR=24.8
120 0 my ($self) = @_;
121 0 my $socksaddr = inet_aton("206.223.45.1");
122  
123 0 my $proto = getprotobyname('tcp');
124 0 my $sin = sockaddr_in(1080, $socksaddr);
125 0 my $fd = IO::Handle->new();
126
127 0 ▶ socket($fd, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
Branch: 1 branch
BranchTrueFalseTotal
socket $fd, 2, 1, $proto or die "socket: $!" 0 0 0
128 0 ▶ connect($fd, $sin) || die "connect: $!";
Branch: 1 branch
BranchTrueFalseTotal
CORE::connect $fd, $sin or die "connect: $!" 0 0 0
129  
130 0 $buffer = pack("ccncccca*c", 4, 1, 443, 198, 81, 3, 52, "jamersepoo", 0);
131 0 syswrite($fd, $buffer, 19);
132  
133 0 return ($fd);
134 }
135  
136 0 ▶sub _connect {
Subroutine _connect: not called CC=3 SCAR=24.8
137 0 my ($self) = @_;
138  
139 0 my $proto = getprotobyname('tcp');
140 0 my $sin = sockaddr_in($self->{port}, $self->{ipaddr});
141 0 my $fd = IO::Handle->new();
142  
143 0 ▶ socket($fd, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
Branch: 1 branch
BranchTrueFalseTotal
socket $fd, 2, 1, $proto or die "socket: $!" 0 0 0
144 0 ▶ connect($fd, $sin) || die "connect: $!";
Branch: 1 branch
BranchTrueFalseTotal
CORE::connect $fd, $sin or die "connect: $!" 0 0 0
145  
146 0 return ($fd);
147 }
148  
149 0 ▶sub connect {
Subroutine connect: not called CC=2 SCAR=17.9
Pod undocumented
150 0 my ($self) = @_;
151 0 my $fd;
152  
153 0 ▶ if ($self->{proxy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'proxy'}) { } 0 0 0
154 0 $fd = &{$self->{proxy}};
155 } else {
156 0 $fd = $self->_connect;
157 }
158  
159 0 $self->{fd} = $fd;
160  
161 0 $foo = $self->write("FLAPON\r\n\r\n", 10);
162  
163 0 $self->recv();
164  
165 0 return $fd;
166 }
167  
168 0 ▶sub recv {
Subroutine recv: not called CC=2 SCAR=17.9
Pod undocumented
169 0 my ($self) = @_;
170 0 my ($buffer, $from, $xfrom) = '';
171 0 my ($fd) = $self->{fd};
172  
173 0 $foo = CORE::sysread($fd, $buffer, 6);
174 0 ▶ if ($foo <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foo <= 0) 0 0 0
175 #print "recv failed! calling signoff....\n";
176 0 $self->callback($SFLAP_SIGNOFF);
177 0 return;
178 }
179  
180 0 my ($id, $chan, $seq, $len, $data) = unpack("aCnn", $buffer);
181 0 $self->debug("sflap recv ($self->{fd}) $foo chan = $chan seq = $seq len = $len\n");
182  
183 0 $foo = CORE::sysread($fd, $data, $len);
184 0 $self->debug(" data = $data\n");
185  
186 0 $self->callback($chan, $data);
187  
188 0 return $buffer;
189 }
190  
191 0 ▶sub send {
Subroutine send: not called CC=3 SCAR=24.8
Pod undocumented
192 0 my ($self, $chan, $data, $length) = @_;
193 0 my $buffer;
194 my $format;
195  
196 0 ▶ if (!$length) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($length) 0 0 0
197 0 $length = length($data);
198 }
199  
200 0 ▶ if ($chan == $SFLAP_DATA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chan == $SFLAP_DATA) { } 0 0 0
201 0 $format = "cCnna*C";
202 0 $length ++;
203 } else {
204 0 $format = "cCnna*";
205 }
206  
207 0 $self->{sequence} ++;
208 $buffer = pack($format, 42, $chan, $self->{sequence},
209 0 $length, $data, 0);
210  
211 0 ($id, $ch, $seq, $len, $data, $nuller) = unpack($format, $buffer);
212  
213 0 $foo = CORE::syswrite($self->{fd}, $buffer, $length + 6);
214 0 $self->debug("sflap send ($self->{fd}) $foo chan = $ch seq = $seq len = $len data = $data\n");
215 }
216  
217 0 ▶sub write {
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
218 0 my ($self, $buffer, $len, $noflap) = @_;
219 0 my $fd = $self->{fd};
220  
221 0 return CORE::syswrite($fd, $buffer, $len);
222 }
223  
224 0 ▶sub flush {
Subroutine flush: not called CC=1 SCAR=6.9
Pod undocumented
225 0 my $self = shift;
226 }
227  
228 1 1;
« TOC.pm ↑ Summary