… | |
… | |
23 | =over 4 |
23 | =over 4 |
24 | |
24 | |
25 | =item overriding internal functions might cause the module to |
25 | =item overriding internal functions might cause the module to |
26 | malfunction with future versions of Net::SNMP |
26 | malfunction with future versions of Net::SNMP |
27 | |
27 | |
28 | =item only leading dots for oids are supported |
|
|
29 | |
|
|
30 | =item error messages will be simpler/different |
28 | =item error messages will be simpler/different |
31 | |
|
|
32 | =item oid components are limited to unsigned 32 bit integers |
|
|
33 | |
29 | |
34 | =item translation will be ignored (all values will be delivered "raw") |
30 | =item translation will be ignored (all values will be delivered "raw") |
35 | |
31 | |
36 | =item a moderately modern (>= C99) C compiler is required |
32 | =item a moderately modern (>= C99) C compiler is required |
37 | |
33 | |
… | |
… | |
50 | use strict qw(vars subs); |
46 | use strict qw(vars subs); |
51 | no warnings; |
47 | no warnings; |
52 | |
48 | |
53 | use Guard; |
49 | use Guard; |
54 | |
50 | |
|
|
51 | use Net::SNMP (); |
55 | use Net::SNMP::PDU (); |
52 | use Net::SNMP::PDU (); |
56 | use Net::SNMP::Message (); |
53 | use Net::SNMP::Message (); |
57 | use Net::SNMP::MessageProcessing (); |
54 | use Net::SNMP::MessageProcessing (); |
58 | |
55 | |
59 | our $VERSION; |
56 | our $VERSION; |
60 | our $old_prepare; |
|
|
61 | |
57 | |
62 | BEGIN { |
58 | BEGIN { |
63 | $VERSION = '0.02'; |
59 | $VERSION = '1.1'; |
64 | |
60 | |
65 | $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements; |
61 | # this overrides many methods inside Net::SNMP and it's submodules |
66 | |
|
|
67 | # this overrides many methods inside |
|
|
68 | require XSLoader; |
62 | require XSLoader; |
69 | XSLoader::load Net::SNMP::XS, $VERSION; |
63 | XSLoader::load Net::SNMP::XS, $VERSION; |
70 | } |
64 | } |
71 | |
65 | |
72 | sub Net::SNMP::MessageProcessing::prepare_data_elements { |
66 | package Net::SNMP::Message; |
73 | my ($self, $msg) = @_; |
|
|
74 | |
67 | |
75 | set_msg $msg, $msg->{_buffer}; |
68 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
76 | scope_guard \&clr_msg; |
69 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
77 | &$old_prepare |
70 | Net::SNMP::XS::set_type NULL , \&_process_null; |
78 | } |
71 | Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
|
|
72 | Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
|
|
73 | Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
|
|
74 | Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
|
|
75 | Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
|
|
76 | Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
|
|
77 | Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
|
|
78 | Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
|
|
79 | Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
|
|
80 | Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
|
|
81 | Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
|
|
82 | Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
|
|
83 | Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
|
|
84 | Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
|
|
85 | Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
|
|
86 | Net::SNMP::XS::set_type TRAP , \&_process_trap; |
|
|
87 | Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
|
|
88 | Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
|
|
89 | Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
|
|
90 | Net::SNMP::XS::set_type REPORT , \&_process_report; |
79 | |
91 | |
|
|
92 | package Net::SNMP::PDU; |
|
|
93 | |
|
|
94 | # var_bind_list hardcodes oid_lex_sort. *sigh* |
|
|
95 | # we copy it 1:1, except for using oid_lex_sort. |
|
|
96 | |
|
|
97 | sub var_bind_list |
80 | { |
98 | { |
81 | package Net::SNMP::Message; |
99 | my ($this, $vbl, $types) = @_; |
82 | |
100 | |
83 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
101 | return if defined($this->{_error}); |
84 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
102 | |
85 | Net::SNMP::XS::set_type NULL , \&_process_null; |
103 | if (@_ > 1) { |
86 | Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
104 | # The VarBindList HASH is being updated from an external |
87 | Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
105 | # source. We need to update the VarBind names ARRAY to |
88 | Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
106 | # correspond to the new keys of the HASH. If the updated |
89 | Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
107 | # information is valid, we will use lexicographical ordering |
90 | Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
108 | # for the ARRAY entries since we do not have a PDU to use |
91 | Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
109 | # to determine the ordering. The ASN.1 types HASH is also |
92 | Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
110 | # updated here if a cooresponding HASH is passed. We double |
93 | Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
111 | # check the mapping by populating the hash with the keys of |
94 | Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
112 | # the VarBindList HASH. |
95 | Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
113 | |
96 | Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
114 | if (!defined($vbl) || (ref($vbl) ne 'HASH')) { |
97 | Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
115 | |
98 | Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
116 | $this->{_var_bind_list} = undef; |
99 | Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
117 | $this->{_var_bind_names} = []; |
100 | Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
118 | $this->{_var_bind_types} = undef; |
101 | Net::SNMP::XS::set_type TRAP , \&_process_trap; |
119 | |
102 | Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
120 | } else { |
103 | Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
121 | |
104 | Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
122 | $this->{_var_bind_list} = $vbl; |
105 | Net::SNMP::XS::set_type REPORT , \&_process_report; |
123 | |
|
|
124 | @{$this->{_var_bind_names}} = Net::SNMP::oid_lex_sort keys %$vbl; |
|
|
125 | |
|
|
126 | if (!defined($types) || (ref($types) ne 'HASH')) { |
|
|
127 | $types = {}; |
|
|
128 | } |
|
|
129 | |
|
|
130 | map { |
|
|
131 | $this->{_var_bind_types}->{$_} = |
|
|
132 | exists($types->{$_}) ? $types->{$_} : undef; |
|
|
133 | } keys(%{$vbl}); |
|
|
134 | |
|
|
135 | } |
|
|
136 | |
|
|
137 | } |
|
|
138 | |
|
|
139 | $this->{_var_bind_list}; |
106 | } |
140 | } |
107 | |
141 | |
108 | 1; |
142 | 1; |
109 | |
143 | |
110 | =head1 AUTHOR |
144 | =head1 AUTHOR |