| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package NSNMP::Mapper; |
|
2
|
|
|
|
|
|
|
# Copyright (c) 2003-2004 AirWave Wireless, Inc. |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without |
|
5
|
|
|
|
|
|
|
# modification, are permitted provided that the following conditions |
|
6
|
|
|
|
|
|
|
# are met: |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# 1. Redistributions of source code must retain the above |
|
9
|
|
|
|
|
|
|
# copyright notice, this list of conditions and the following |
|
10
|
|
|
|
|
|
|
# disclaimer. |
|
11
|
|
|
|
|
|
|
# 2. Redistributions in binary form must reproduce the above |
|
12
|
|
|
|
|
|
|
# copyright notice, this list of conditions and the following |
|
13
|
|
|
|
|
|
|
# disclaimer in the documentation and/or other materials provided |
|
14
|
|
|
|
|
|
|
# with the distribution. |
|
15
|
|
|
|
|
|
|
# 3. The name of the author may not be used to endorse or |
|
16
|
|
|
|
|
|
|
# promote products derived from this software without specific |
|
17
|
|
|
|
|
|
|
# prior written permission. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
|
20
|
|
|
|
|
|
|
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21
|
|
|
|
|
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
22
|
|
|
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|
23
|
|
|
|
|
|
|
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
24
|
|
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
|
25
|
|
|
|
|
|
|
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
26
|
|
|
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
27
|
|
|
|
|
|
|
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
28
|
|
|
|
|
|
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
29
|
|
|
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# On optimizing: |
|
33
|
|
|
|
|
|
|
# I tried encoding the OIDs in BER before comparing them, so as to |
|
34
|
|
|
|
|
|
|
# avoid the (?:\.|\z) thingy and the various leading-dot crap, and |
|
35
|
|
|
|
|
|
|
# also to look at less bytes. Got it working pretty soon, but the |
|
36
|
|
|
|
|
|
|
# time test (matching 500 OIDs against a mapper with 100 similar OIDs |
|
37
|
|
|
|
|
|
|
# in it, getting a hit every time) slowed from 35 ms to 47 ms, even |
|
38
|
|
|
|
|
|
|
# though the OID lookups were cached. Might be worthwhile if the OIDs |
|
39
|
|
|
|
|
|
|
# were already in that format, e.g. for sorting or because they just |
|
40
|
|
|
|
|
|
|
# came across the wire (or are about to go back), but I'll cross that |
|
41
|
|
|
|
|
|
|
# bridge when I come to it. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
|
44
|
37
|
|
|
37
|
0
|
1107
|
my ($class, %args) = @_; |
|
45
|
37
|
|
|
|
|
202
|
my $self = bless { table => {} }, $class; |
|
46
|
37
|
|
|
|
|
214
|
while (my ($key, $value) = each %args) { |
|
47
|
145
|
|
|
|
|
704
|
$key =~ s/\A\.//; |
|
48
|
145
|
|
|
|
|
592
|
$self->{table}{$key} = $value; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
37
|
|
|
|
|
71
|
my $bigre = '\A(' . (join '|', map { "\Q$_\E" } keys %{$self->{table}}) . ')(?:\.|\z)(.*)'; |
|
|
145
|
|
|
|
|
709
|
|
|
|
37
|
|
|
|
|
310
|
|
|
51
|
37
|
|
|
|
|
1814
|
$self->{bigre} = qr/$bigre/; |
|
52
|
37
|
|
|
|
|
203
|
return $self; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# XXX note this interface is really bug-prone in scalar context |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub map { |
|
58
|
1151
|
|
|
1151
|
0
|
3039
|
my ($self, $oid) = @_; |
|
59
|
1151
|
|
|
|
|
2487
|
$oid =~ s/\A\.//; |
|
60
|
1151
|
100
|
|
|
|
8288
|
if ($oid =~ $self->{bigre}) { |
|
61
|
1144
|
|
|
|
|
2505
|
my ($key, $instance) = ($1, $2); |
|
62
|
1144
|
100
|
|
|
|
6136
|
return ($self->{table}{$key}, ($instance eq '' ? undef : $instance)); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
7
|
|
|
|
|
31
|
return (undef, undef); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |