| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::IMP::Remote::DualvarMapping; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
8
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
58
|
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
37
|
|
|
5
|
2
|
|
|
2
|
|
11
|
use Net::IMP::Remote::Protocol; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
120
|
|
|
6
|
2
|
|
|
2
|
|
8
|
use Net::IMP qw(:DEFAULT :log IMP_DATA_TYPES ); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
369
|
|
|
7
|
2
|
|
|
2
|
|
17
|
use Net::IMP::Debug; |
|
|
2
|
|
|
|
|
51
|
|
|
|
2
|
|
|
|
|
15
|
|
|
8
|
2
|
|
|
2
|
|
187
|
use Exporter 'import'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2002
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw(rpc_i2d rpc_d2i); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# data type mapping int -> dualvar |
|
12
|
|
|
|
|
|
|
# basic data types are added, we check for more additional types in |
|
13
|
|
|
|
|
|
|
# IMPRPC_GET_INTERFACE and IMPRPC_SET_INTERFACE |
|
14
|
|
|
|
|
|
|
my %dt_i2d = ( |
|
15
|
|
|
|
|
|
|
IMP_DATA_STREAM+0 => IMP_DATA_STREAM, |
|
16
|
|
|
|
|
|
|
IMP_DATA_PACKET+0 => IMP_DATA_PACKET, |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _dt_i2d { |
|
20
|
0
|
|
|
0
|
|
0
|
my $i = shift; |
|
21
|
0
|
|
|
|
|
0
|
my $v = $dt_i2d{$i}; |
|
22
|
0
|
0
|
|
|
|
0
|
return $v if defined $v; |
|
23
|
0
|
|
|
|
|
0
|
for ( IMP_DATA_TYPES() ) { |
|
24
|
0
|
0
|
|
|
|
0
|
exists $dt_i2d{ $_+0 } and next; |
|
25
|
0
|
|
|
|
|
0
|
$dt_i2d{ $_+0 } = $_; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
0
|
|
|
|
|
0
|
$v = $dt_i2d{$i}; |
|
28
|
0
|
0
|
|
|
|
0
|
return $v if defined $v; |
|
29
|
0
|
|
|
|
|
0
|
die "cannot map $i to known data type"; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# return type mapping int -> dualvar |
|
33
|
|
|
|
|
|
|
my %rt_i2d = map { ( $_+0 => $_ ) } ( |
|
34
|
|
|
|
|
|
|
IMP_PASS, |
|
35
|
|
|
|
|
|
|
IMP_PASS_PATTERN, |
|
36
|
|
|
|
|
|
|
IMP_PREPASS, |
|
37
|
|
|
|
|
|
|
IMP_DENY, |
|
38
|
|
|
|
|
|
|
IMP_DROP, |
|
39
|
|
|
|
|
|
|
IMP_FATAL, |
|
40
|
|
|
|
|
|
|
IMP_TOSENDER, |
|
41
|
|
|
|
|
|
|
IMP_REPLACE, |
|
42
|
|
|
|
|
|
|
IMP_REPLACE_LATER, |
|
43
|
|
|
|
|
|
|
IMP_PAUSE, |
|
44
|
|
|
|
|
|
|
IMP_CONTINUE, |
|
45
|
|
|
|
|
|
|
IMP_LOG, |
|
46
|
|
|
|
|
|
|
IMP_PORT_OPEN, |
|
47
|
|
|
|
|
|
|
IMP_PORT_CLOSE, |
|
48
|
|
|
|
|
|
|
IMP_ACCTFIELD, |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# log level mapping int -> dualvar |
|
52
|
|
|
|
|
|
|
my %ll_i2d = map { ( $_+0 => $_ ) } ( |
|
53
|
|
|
|
|
|
|
IMP_LOG_DEBUG, |
|
54
|
|
|
|
|
|
|
IMP_LOG_INFO, |
|
55
|
|
|
|
|
|
|
IMP_LOG_NOTICE, |
|
56
|
|
|
|
|
|
|
IMP_LOG_WARNING, |
|
57
|
|
|
|
|
|
|
IMP_LOG_ERR, |
|
58
|
|
|
|
|
|
|
IMP_LOG_CRIT, |
|
59
|
|
|
|
|
|
|
IMP_LOG_ALERT, |
|
60
|
|
|
|
|
|
|
IMP_LOG_EMERG, |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# op mapping int -> dualvar |
|
64
|
|
|
|
|
|
|
my %op_i2d = map { ( $_+0 => $_ ) } ( |
|
65
|
|
|
|
|
|
|
IMPRPC_GET_INTERFACE, |
|
66
|
|
|
|
|
|
|
IMPRPC_SET_INTERFACE, |
|
67
|
|
|
|
|
|
|
IMPRPC_NEW_ANALYZER, |
|
68
|
|
|
|
|
|
|
IMPRPC_DEL_ANALYZER, |
|
69
|
|
|
|
|
|
|
IMPRPC_DATA, |
|
70
|
|
|
|
|
|
|
IMPRPC_SET_VERSION, |
|
71
|
|
|
|
|
|
|
IMPRPC_EXCEPTION, |
|
72
|
|
|
|
|
|
|
IMPRPC_INTERFACE, |
|
73
|
|
|
|
|
|
|
IMPRPC_RESULT, |
|
74
|
|
|
|
|
|
|
); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my %args_d2i = ( |
|
77
|
|
|
|
|
|
|
IMPRPC_GET_INTERFACE+0 => sub { |
|
78
|
|
|
|
|
|
|
# @_ -> list< data_type_id, list > provider_ifs |
|
79
|
|
|
|
|
|
|
my @rv; |
|
80
|
|
|
|
|
|
|
for my $if (@_) { |
|
81
|
|
|
|
|
|
|
my ($dtype,$rtypes) = @$if; |
|
82
|
|
|
|
|
|
|
if ( defined $dtype ) { |
|
83
|
|
|
|
|
|
|
$dt_i2d{ $dtype+0 } ||= $dtype; |
|
84
|
|
|
|
|
|
|
$dtype += 0 |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
if ( $rtypes ) { |
|
87
|
|
|
|
|
|
|
push @rv, [ $dtype , [ map { $_+0 } @$rtypes ]]; |
|
88
|
|
|
|
|
|
|
} else { |
|
89
|
|
|
|
|
|
|
push @rv, [ $dtype ] |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
return @rv; |
|
93
|
|
|
|
|
|
|
}, |
|
94
|
|
|
|
|
|
|
IMPRPC_SET_INTERFACE+0 => sub { |
|
95
|
|
|
|
|
|
|
# @_ -> > provider_if |
|
96
|
|
|
|
|
|
|
my ($dtype,$rtypes) = @{$_[0]}; |
|
97
|
|
|
|
|
|
|
my @rt = map { $_+0 } @$rtypes; |
|
98
|
|
|
|
|
|
|
if ( ! defined $dtype ) { |
|
99
|
|
|
|
|
|
|
return [ undef , \@rt ] |
|
100
|
|
|
|
|
|
|
} else { |
|
101
|
|
|
|
|
|
|
$dt_i2d{ $dtype+0 } ||= $dtype; |
|
102
|
|
|
|
|
|
|
return [ $dtype+0 , \@rt ] |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
}, |
|
105
|
|
|
|
|
|
|
IMPRPC_DATA+0 => sub { |
|
106
|
|
|
|
|
|
|
# @_ -> analyzer_id, dir, offset, data_type_id, char data[] |
|
107
|
|
|
|
|
|
|
return (@_[0,1,2],$_[3]+0,$_[4]); |
|
108
|
|
|
|
|
|
|
}, |
|
109
|
|
|
|
|
|
|
IMPRPC_RESULT+0 => sub { |
|
110
|
|
|
|
|
|
|
# @_ -> analyzer_id, result_type_id, ... |
|
111
|
|
|
|
|
|
|
my ($id,$rtype) = @_; |
|
112
|
|
|
|
|
|
|
if ( $rtype == IMP_LOG ) { |
|
113
|
|
|
|
|
|
|
# id,type - dir,offset,len,level,msg,@extmsg |
|
114
|
|
|
|
|
|
|
return ($id,$rtype+0,@_[2,3,4],$_[5]+0,@_[6..$#_]); |
|
115
|
|
|
|
|
|
|
} else { |
|
116
|
|
|
|
|
|
|
return ($id,$rtype+0,@_[2..$#_]); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
}, |
|
119
|
|
|
|
|
|
|
); |
|
120
|
|
|
|
|
|
|
$args_d2i{ IMPRPC_INTERFACE+0 } = $args_d2i{ IMPRPC_GET_INTERFACE+0 }; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my %args_i2d = ( |
|
124
|
|
|
|
|
|
|
IMPRPC_GET_INTERFACE+0 => sub { |
|
125
|
|
|
|
|
|
|
# @_ -> list< data_type_id, list > provider_ifs |
|
126
|
|
|
|
|
|
|
my @rv; |
|
127
|
|
|
|
|
|
|
for my $if (@_) { |
|
128
|
|
|
|
|
|
|
my ($dtype,$rtypes) = @$if; |
|
129
|
|
|
|
|
|
|
$dtype = $dt_i2d{$dtype} || _dt_i2d($dtype) if defined $dtype; |
|
130
|
|
|
|
|
|
|
if ( $rtypes ) { |
|
131
|
|
|
|
|
|
|
push @rv, [ $dtype, [ map { $rt_i2d{$_} } @$rtypes ]]; |
|
132
|
|
|
|
|
|
|
} else { |
|
133
|
|
|
|
|
|
|
push @rv, [ $dtype ] |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
return @rv; |
|
137
|
|
|
|
|
|
|
}, |
|
138
|
|
|
|
|
|
|
IMPRPC_SET_INTERFACE+0 => sub { |
|
139
|
|
|
|
|
|
|
# @_ -> > provider_if |
|
140
|
|
|
|
|
|
|
my ($dtype,$rtypes) = @{$_[0]}; |
|
141
|
|
|
|
|
|
|
my @rt = map { defined($_) ? $rt_i2d{$_} :undef } @$rtypes; |
|
142
|
|
|
|
|
|
|
$dtype = $dt_i2d{$dtype} || _dt_i2d($dtype) if defined $dtype; |
|
143
|
|
|
|
|
|
|
return [ $dtype,\@rt ]; |
|
144
|
|
|
|
|
|
|
}, |
|
145
|
|
|
|
|
|
|
IMPRPC_DATA+0 => sub { |
|
146
|
|
|
|
|
|
|
# @_ -> analyzer_id, dir, offset, data_type_id, char data[] |
|
147
|
|
|
|
|
|
|
return (@_[0,1,2],$dt_i2d{$_[3]} || _dt_i2d($_[3]),$_[4]); |
|
148
|
|
|
|
|
|
|
}, |
|
149
|
|
|
|
|
|
|
IMPRPC_RESULT+0 => sub { |
|
150
|
|
|
|
|
|
|
# @_ -> analyzer_id, result_type_id, ... |
|
151
|
|
|
|
|
|
|
my ($id,$rtype) = @_; |
|
152
|
|
|
|
|
|
|
if ( $rtype == IMP_LOG ) { |
|
153
|
|
|
|
|
|
|
# id,type - dir,offset,len,level,msg,@extmsg |
|
154
|
|
|
|
|
|
|
return ($id,$rt_i2d{$rtype},@_[2,3,4],$ll_i2d{$_[5]},@_[6..$#_]); |
|
155
|
|
|
|
|
|
|
} else { |
|
156
|
|
|
|
|
|
|
return ($id,$rt_i2d{$rtype},@_[2..$#_]); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
}, |
|
159
|
|
|
|
|
|
|
); |
|
160
|
|
|
|
|
|
|
$args_i2d{ IMPRPC_INTERFACE+0 } = $args_i2d{ IMPRPC_GET_INTERFACE+0 }; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub rpc_i2d { |
|
163
|
22
|
|
|
22
|
0
|
30
|
my ($op,@args) = @{$_[0]}; |
|
|
22
|
|
|
|
|
57
|
|
|
164
|
22
|
|
|
|
|
54
|
$op = $op_i2d{$op}; |
|
165
|
22
|
100
|
|
|
|
88
|
my $sub = $args_i2d{$op+0} or return [$op,@args]; |
|
166
|
|
|
|
|
|
|
#$DEBUG && debug("calling args_i2d for $op"); |
|
167
|
16
|
|
|
|
|
44
|
return [ $op, $sub->(@args) ]; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub rpc_d2i { |
|
171
|
24
|
|
|
24
|
0
|
27
|
my ($op,@args) = @{$_[0]}; |
|
|
24
|
|
|
|
|
75
|
|
|
172
|
24
|
100
|
|
|
|
196
|
my $sub = $args_d2i{$op+0} or return [ $op+0,@args ]; |
|
173
|
|
|
|
|
|
|
#$DEBUG && debug("calling args_d2i for $op"); |
|
174
|
16
|
|
|
|
|
49
|
return [ $op+0,$sub->(@args) ]; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |