IMP.pm

filter: Statementstmt 80.8% 118 / 146 Branchbran 11.1% 2 / 18 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 94.5% 35 / 37 Podpod 0.0% 0 / 2 totaltotal 73.2% 156 / 213 CC 12 SCAR 31.9
CC
12
Cov
71%
IMP_DATA
93.6
IMP_DATA_TYPES
2.0
__ANON__
2.0
CRAP 24.2
« IMP/Base.pm ↑ Summary IMP/SessionLog.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Net::IMP;
5 8 our $VERSION = '0.633';
6  
7 8 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Scalar::Util 'dualvar';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # map set_debug into local namespace for convinience, so that one
11 # can call Net::IMP->set_debug instead of Net::IMP::Debug->set_debug
12 8 ▶use Net::IMP::Debug 'set_debug';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 our @EXPORT = qw(
16 IMP_PASS
17 IMP_PASS_PATTERN
18 IMP_PREPASS
19 IMP_DENY
20 IMP_DROP
21 IMP_TOSENDER
22 IMP_REPLACE
23 IMP_REPLACE_LATER
24 IMP_PAUSE
25 IMP_CONTINUE
26 IMP_LOG
27 IMP_PORT_OPEN
28 IMP_PORT_CLOSE
29 IMP_ACCTFIELD
30 IMP_FATAL
31 IMP_MAXOFFSET
32 IMP_DATA_STREAM
33 IMP_DATA_PACKET
34 );
35  
36 8 my @log_levels = qw(
37 IMP_LOG_DEBUG
38 IMP_LOG_INFO
39 IMP_LOG_NOTICE
40 IMP_LOG_WARNING
41 IMP_LOG_ERR
42 IMP_LOG_CRIT
43 IMP_LOG_ALERT
44 IMP_LOG_EMERG
45 );
46 8 our @EXPORT_OK = (@log_levels, 'IMP_DATA','IMP_DATA_TYPES', 'IMP_PASS_IF_BUSY');
47 8 our %EXPORT_TAGS = ( log => \@log_levels );
48  
49 # data types/protocols
50 # These two are the basic types, more application specific types might
51 # be defined somewhere else and be mapped to a number within supported_dtypes.
52 # The only important thing is, that streaming data should be <0, while
53 # packetized data (like HTTP header or UDP datagrams) should be > 0
54 # If no explicit type is given in sub data, it will assume IMP_DATA_STREAM.
55 8 ▶use constant IMP_DATA_STREAM => dualvar(-1,'imp.data.stream');
Subroutine BEGIN: called CC=1 SCAR=0.0
56 8 ▶use constant IMP_DATA_PACKET => dualvar(+1,'imp.data.packet');
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58  
59 # the numerical order of the constants describes priority when
60 # cascading modules, e.g. replacement has a higher value then
61 # pass and gets thus forwarded as the cause for the data
62  
63 ### information only
64 8 ▶use constant IMP_LOG => dualvar(0x0001,"log");
Subroutine BEGIN: called CC=1 SCAR=0.0
65 8 ▶use constant IMP_PORT_OPEN => dualvar(0x0002,"port_open");
Subroutine BEGIN: called CC=1 SCAR=0.0
66 8 ▶use constant IMP_PORT_CLOSE => dualvar(0x0003,"port_close");
Subroutine BEGIN: called CC=1 SCAR=0.0
67 8 ▶use constant IMP_ACCTFIELD => dualvar(0x0004,"acctfield");
Subroutine BEGIN: called CC=1 SCAR=0.0
68 ### flow control
69 8 ▶use constant IMP_PAUSE => dualvar(0x0010,"pause");
Subroutine BEGIN: called CC=1 SCAR=0.0
70 8 ▶use constant IMP_CONTINUE => dualvar(0x0011,"continue");
Subroutine BEGIN: called CC=1 SCAR=0.0
71 8 ▶use constant IMP_REPLACE_LATER => dualvar(0x0012,"replace_later");
Subroutine BEGIN: called CC=1 SCAR=0.0
72 ### keep data
73 8 ▶use constant IMP_PASS => dualvar(0x1001,"pass");
Subroutine BEGIN: called CC=1 SCAR=0.0
74 8 ▶use constant IMP_PASS_PATTERN => dualvar(0x1002,"pass_pattern");
Subroutine BEGIN: called CC=1 SCAR=0.0
75 8 ▶use constant IMP_PREPASS => dualvar(0x1003,"prepass");
Subroutine BEGIN: called CC=1 SCAR=0.0
76 ### change data
77 8 ▶use constant IMP_TOSENDER => dualvar(0x1010,"tosender");
Subroutine BEGIN: called CC=1 SCAR=0.0
78 8 ▶use constant IMP_REPLACE => dualvar(0x1011,"replace");
Subroutine BEGIN: called CC=1 SCAR=0.0
79 ### affect whole connection
80 8 ▶use constant IMP_DENY => dualvar(0x1100,"deny");
Subroutine BEGIN: called CC=1 SCAR=0.0
81 8 ▶use constant IMP_DROP => dualvar(0x1101,"drop");
Subroutine BEGIN: called CC=1 SCAR=0.0
82 8 ▶use constant IMP_FATAL => dualvar(0x1102,"fatal");
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 # these return values still get sent if the data provider is busy
85 # the most important are on top
86 8 use constant IMP_PASS_IF_BUSY => [
87 IMP_FATAL,
88 IMP_DENY,
89 IMP_DROP,
90 IMP_PAUSE,
91 IMP_CONTINUE,
92 IMP_ACCTFIELD
93 8 ▶];
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95  
96 # marker for (pre)pass to Infinite for IMP_PASS, IMP_PREPASS
97 8 ▶use constant IMP_MAXOFFSET => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 # log levels for IMP_LOG
100 # these are modeled analog to syslog levels
101 8 ▶use constant IMP_LOG_DEBUG => dualvar(1,'debug');
Subroutine BEGIN: called CC=1 SCAR=0.0
102 8 ▶use constant IMP_LOG_INFO => dualvar(2,'info');
Subroutine BEGIN: called CC=1 SCAR=0.0
103 8 ▶use constant IMP_LOG_NOTICE => dualvar(3,'notice');
Subroutine BEGIN: called CC=1 SCAR=0.0
104 8 ▶use constant IMP_LOG_WARNING => dualvar(4,'warning');
Subroutine BEGIN: called CC=1 SCAR=0.0
105 8 ▶use constant IMP_LOG_ERR => dualvar(5,'error');
Subroutine BEGIN: called CC=1 SCAR=0.0
106 8 ▶use constant IMP_LOG_CRIT => dualvar(6,'critical');
Subroutine BEGIN: called CC=1 SCAR=0.0
107 8 ▶use constant IMP_LOG_ALERT => dualvar(7,'alert');
Subroutine BEGIN: called CC=1 SCAR=0.0
108 8 ▶use constant IMP_LOG_EMERG => dualvar(8,'emergency');
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110  
111 # helper function to define new IMP_DATA_* types for protocols
112 {
113 8 my @dualvars = ( IMP_DATA_STREAM, IMP_DATA_PACKET );
114 0 ▶ sub IMP_DATA_TYPES { return @dualvars }
Subroutine IMP_DATA_TYPES: not called CC=1 SCAR=6.9
Pod undocumented
115  
116 8 my %atoi = map {( "$_" => $_+0 )} @dualvars;
117 8 my %itoa = map {( $_+0 => "$_" )} @dualvars;
118  
119 # $basename - name which gets used in constant name, e.g. 'http' makes
120 # IMP_DATA_HTTP_..... Best would be name of IP service.
121 # - if name[number] will use number as base type number
122 # - if name[other_name+number] will base types on already defined
123 # types with number added as offset
124 # - if no number given it will use port name from getservbyname,
125 # multiplied with 0x10000 and die if no such service is defined
126 # @def: list of defname => [+-]offset which will result in a definition
127 # of IMP_DATA_BASENAME_DEFNAME => [+-](base+offset), e.g. '+' for packet
128 # types and '-' for stream types
129 sub IMP_DATA {
130 1 ▶ my ($basename,@def) = @_;
Subroutine IMP_DATA: called CC=12 SCAR=45.4
Pod undocumented
131 1 my $basenum;
132 1 ▶ if ( $basename =~s{\[(?:(\w+)\+)?(\d+)\]$}{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($basename =~ s/\[(?:(\w+)\+)?(\d+)\]$//) { } 0 1 1
133 0 (my $base,$basenum) = ($1,$2);
134 0 ▶ if ( $base ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base) 0 0 0
135 0 ▶ my $offset = $atoi{$base}
Branch: 1 branch
BranchTrueFalseTotal
my $offset = $atoi{$base} or croak("cannot find base type $base") 0 0 0
136 or croak("cannot find base type $base");
137 0 $basenum += $offset;
138 }
139 } else {
140 1 ▶ $basenum = getservbyname($basename,'tcp' )
Branch: 1 branch
BranchTrueFalseTotal
$basenum = getservbyname($basename, "tcp") || getservbyname($basename, "udp") or croak("cannot determine id for $basename") 1 0 1
Condition33%1/3
getservbyname($basename, 'tcp') || getservbyname($basename, 'udp')
l!l&&r!l&&!r
001
MC/DC0%0/2
getservbyname($basename, 'tcp') || getservbyname($basename, 'udp')
getservbyname($basename, 'tcp') getservbyname($basename, 'udp')
Truth table33%1/3
A || B
A= getservbyname($basename, 'tcp')B= getservbyname($basename, 'udp')
ABresult
1X1
011
000
141 || getservbyname($basename,'udp' )
142 or croak("cannot determine id for $basename");
143 0 $basenum = $basenum << 16;
144 }
145  
146 0 my @const;
147  
148 0 my $pkg = caller;
149 0 unshift(@def,'',0);
150 0 ▶ while (@def) {
Branch: 1 branch
BranchTrueFalseTotal
if (@def) 0 0 0
151 0 my $name = shift(@def);
152 0 my $diff = shift(@def);
153 0 ▶ my $lname = $name ne '' ? "$basename.$name" : $basename;
Branch: 1 branch
BranchTrueFalseTotal
$name ne '' ? : 0 0 0
154 0 ▶ croak("$lname already defined") if exists $atoi{$lname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $atoi{$lname} 0 0 0
155 0 ▶ my $lnum = $diff>=0 ? $basenum + $diff : -$basenum+$diff;
Branch: 1 branch
BranchTrueFalseTotal
$diff >= 0 ? : 0 0 0
156 0 ▶ if ( my $s = $itoa{$lnum} || $itoa{-$lnum} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $itoa{$lnum} || $itoa{-$lnum}) 0 0 0
Condition0%0/3
$itoa{$lnum} || $itoa{-$lnum}
l!l&&r!l&&!r
000
MC/DC0%0/2
$itoa{$lnum} || $itoa{-$lnum}
$itoa{$lnum} $itoa{-$lnum}
Truth table0%0/3
A || B
A= $itoa{$lnum}B= $itoa{-$lnum}
ABresult
1X1
011
000
157 0 croak("id $lnum alreday used for $s");
158 }
159 0 $atoi{$lname} = $lnum;
160 0 $itoa{$lnum} = $lname;
161  
162 0 my $string = "imp.data.$lname";
163 0 ( my $const = uc($string) )=~s{\.}{_}g;
164 0 push @const,$const;
165  
166 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
167 0 my $var = dualvar($lnum,$string);
168 0 ▶ *{ "${pkg}::$const" } = sub () { $var };
Subroutine __ANON__: not called CC=1 SCAR=6.9
169 0 push @dualvars, $var;
170 }
171  
172 0 return @const;
173 }
174  
175 }
176  
177  
178 8 1;
179  
180 __END__
« IMP/Base.pm ↑ Summary IMP/SessionLog.pm »