ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-SNMP-XS/XS.pm
(Generate patch)

Comparing Net-SNMP-XS/XS.pm (file contents):
Revision 1.6 by root, Thu Apr 9 10:08:25 2009 UTC vs.
Revision 1.16 by root, Fri Dec 21 11:21:06 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines