Produced by Araxis Merge on 9/25/2018 2:13:03 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\snmp | SnmpMsg.java | Mon Jan 22 14:46:50 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\snmp | SnmpMsg.java | Wed Sep 12 16:26:25 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 950 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 200 1, 2006, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package co m.sun.jmx. snmp; | |
27 | ||
28 | import com .sun.jmx.s nmp.SnmpSe curityPara meters; | |
29 | // java im ports | |
30 | // | |
31 | import jav a.util.Vec tor; | |
32 | import jav a.net.Inet Address; | |
33 | ||
34 | ||
35 | import com .sun.jmx.s nmp.SnmpSt atusExcept ion; | |
36 | /** | |
37 | * A parti ally decod ed represe ntation of an SNMP p acket. It contains | |
38 | * the inf ormation c ontained i n any SNMP message ( SNMPv1, SN MPv2 or | |
39 | * SNMPv3) . | |
40 | * <p><b>T his API is a Sun Mic rosystems internal A PI and is subject | |
41 | * to chan ge without notice.</ b></p> | |
42 | * @since 1.5 | |
43 | */ | |
44 | public abs tract clas s SnmpMsg implements SnmpDefin itions { | |
45 | /** | |
46 | * The protocol version. | |
47 | * <P> <CODE>deco deMessage< /CODE> and <CODE>enc odeMessage </CODE> do not | |
48 | * per form any c heck on th is value. | |
49 | * <BR ><CODE>dec odeSnmpPdu </CODE> an d <CODE>en codeSnmpPd u</CODE> o nly | |
50 | * acc ept the v alues 0 (f or SNMPv1) , 1 (for S NMPv2) and 3 (for SN MPv3). | |
51 | */ | |
52 | public int versi on = 0; | |
53 | ||
54 | /** | |
55 | * Enc oding of t he PDU. | |
56 | * <P> This is us ually the BER encodi ng of the PDU's synt ax | |
57 | * def ined in RF C1157 and RFC1902. H owever, th is can be authentica ted | |
58 | * or encrypted data (but you need t o implemen ted your o wn | |
59 | * <CO DE>SnmpPdu Factory</C ODE> class ). | |
60 | */ | |
61 | public byte[] da ta = null; | |
62 | ||
63 | /** | |
64 | * Num ber of use ful bytes in the <CO DE>data</C ODE> field . | |
65 | */ | |
66 | public int dataL ength = 0; | |
67 | ||
68 | /** | |
69 | * Sou rce or des tination a ddress. | |
70 | * <BR >For an in coming mes sage it's the source . | |
71 | * For an outgoi ng message it's the destinatio n. | |
72 | */ | |
73 | public InetAddre ss address = null; | |
74 | ||
75 | /** | |
76 | * Sou rce or des tination p ort. | |
77 | * <BR >For an in coming mes sage it's the source . | |
78 | * For an outgoi ng message it's the destinatio n. | |
79 | */ | |
80 | public int PORT
|
|
81 | /** | |
82 | * Sec urity para meters. Co ntain info rmations a ccording t o Security Model (Us m, communi ty string based, ... ). | |
83 | */ | |
84 | public SnmpSecur ityParamet ers securi tyParamete rs = null; | |
85 | /** | |
86 | * Ret urns the e ncoded SNM P version present in the passe d byte arr ay. | |
87 | * @pa ram data T he unmarsh alled SNMP message. | |
88 | * @re turn The S NMP versio n (0, 1 or 3). | |
89 | */ | |
90 | public static in t getProto colVersion (byte[] da ta) | |
91 | th rows SnmpS tatusExcep tion { | |
92 | in t version = 0; | |
93 | Be rDecoder b dec = null ; | |
94 | tr y { | |
95 | bdec = n ew BerDeco der(data); | |
96 | bdec.ope nSequence( ); | |
97 | version = bdec.fet chInteger( ); | |
98 | } | |
99 | ca tch(BerExc eption x) { | |
100 | throw ne w SnmpStat usExceptio n("Invalid encoding" ) ; | |
101 | } | |
102 | tr y { | |
103 | bdec.clo seSequence (); | |
104 | } | |
105 | ca tch(BerExc eption x) { | |
106 | } | |
107 | re turn versi on; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Ret urns the a ssociated request ID . | |
112 | * @pa ram data T he flat me ssage. | |
113 | * @re turn The r equest ID. | |
114 | */ | |
115 | public abstract int getReq uestId(byt e[] data) throws Snm pStatusExc eption; | |
116 | ||
117 | /** | |
118 | * Enc odes this message an d puts the result in the speci fied byte array. | |
119 | * For internal use only. | |
120 | * | |
121 | * @pa ram output Bytes An a rray to re ceive the resulting encoding. | |
122 | * | |
123 | * @ex ception Ar rayIndexOu tOfBoundsE xception I f the resu lt does no t fit | |
124 | * i nto the sp ecified ar ray. | |
125 | */ | |
126 | public abstract int encode Message(by te[] outpu tBytes) | |
127 | th rows SnmpT ooBigExcep tion; | |
128 | ||
129 | /** | |
130 | * Dec odes the s pecified b ytes and i nitializes this mess age. | |
131 | * For internal use only. | |
132 | * | |
133 | * @pa ram inputB ytes The b ytes to be decoded. | |
134 | * | |
135 | * @ex ception Sn mpStatusEx ception If the speci fied bytes are not a valid enc oding. | |
136 | */ | |
137 | public abstract void decod eMessage(b yte[] inpu tBytes, in t byteCoun t) | |
138 | th rows SnmpS tatusExcep tion; | |
139 | ||
140 | /** | |
141 | * Ini tializes t his messag e with the specified <CODE>pdu </CODE>. | |
142 | * <P> | |
143 | * Thi s method i nitializes the data field with an array of | |
144 | * <CO DE>maxData Length</CO DE> bytes. It encode s the <COD E>pdu</COD E>. | |
145 | * The resulting encoding is stored in the dat a field | |
146 | * and the lengt h of the e ncoding is stored in <CODE>dat aLength</C ODE>. | |
147 | * <p> | |
148 | * If the encodi ng length exceeds <C ODE>maxDat aLength</C ODE>, | |
149 | * the method th rows an ex ception. | |
150 | * | |
151 | * @pa ram pdu Th e PDU to b e encoded. | |
152 | * @pa ram maxDat aLength Th e maximum length per mitted for the data field. | |
153 | * | |
154 | * @ex ception Sn mpStatusEx ception If the speci fied <CODE >pdu</CODE > is not v alid. | |
155 | * @ex ception Sn mpTooBigEx ception If the resul ting encod ing does n ot fit | |
156 | * int o <CODE>ma xDataLengt h</CODE> b ytes. | |
157 | * @ex ception Ar rayIndexOu tOfBoundsE xception I f the enco ding excee ds <CODE>m axDataLeng th</CODE>. | |
158 | */ | |
159 | public abstract void encod eSnmpPdu(S nmpPdu pdu , int maxD ataLength) | |
160 | th rows SnmpS tatusExcep tion, Snmp TooBigExce ption; | |
161 | ||
162 | ||
163 | /** | |
164 | * Get s the PDU encoded in this mess age. | |
165 | * <P> | |
166 | * Thi s method d ecodes the data fiel d and retu rns the re sulting PD U. | |
167 | * | |
168 | * @re turn The r esulting P DU. | |
169 | * @ex ception Sn mpStatusEx ception If the encod ing is not valid. | |
170 | */ | |
171 | public abstract SnmpPdu de codeSnmpPd u() | |
172 | th rows SnmpS tatusExcep tion; | |
173 | ||
174 | /** | |
175 | * Dum ps the con tent of a byte buffe r using he xadecimal form. | |
176 | * | |
177 | * @pa ram b The buffer to dump. | |
178 | * @pa ram offset The posit ion of the first byt e to be du mped. | |
179 | * @pa ram len Th e number o f bytes to be dumped starting from offse t. | |
180 | * | |
181 | * @re turn The s tring cont aining the dump. | |
182 | */ | |
183 | public static St ring dumpH exBuffer(b yte [] b, int offset , int len) { | |
184 | St ringBuffer buf = new StringBuf fer(len << 1) ; | |
185 | in t k = 1 ; | |
186 | in t flen = o ffset + le n ; | |
187 | ||
188 | fo r (int i = offset; i < flen ; i++) { | |
189 | int j = b[i] & 0xF F ; | |
190 | buf.appe nd(Charact er.forDigi t((j >>> 4 ) , 16)) ; | |
191 | buf.appe nd(Charact er.forDigi t((j & 0x0 F), 16)) ; | |
192 | k++ ; | |
193 | if (k%16 == 0) { | |
194 | buf. append('\n ') ; | |
195 | k = 1 ; | |
196 | } else | |
197 | buf. append(' ' ) ; | |
198 | } | |
199 | re turn buf.t oString() ; | |
200 | } | |
201 | ||
202 | /** | |
203 | * Dum ps this me ssage in a string. | |
204 | * | |
205 | * @re turn The s tring cont aining the dump. | |
206 | */ | |
207 | public String pr intMessage () { | |
208 | St ringBuffer sb = new StringBuff er() ; | |
209 | sb .append("V ersion: ") ; | |
210 | sb .append(ve rsion) ; | |
211 | sb .append("\ n") ; | |
212 | if (data == null) { | |
213 | sb.appen d("Data: n ull") ; | |
214 | } | |
215 | el se { | |
216 | sb.appen d("Data: { \n") ; | |
217 | sb.appen d(dumpHexB uffer(data , 0, dataL ength)) ; | |
218 | sb.appen d("\n}\n") ; | |
219 | } | |
220 | ||
221 | re turn sb.to String() ; | |
222 | } | |
223 | ||
224 | /** | |
225 | * For SNMP Runt ime privat e use only . | |
226 | */ | |
227 | public void enco deVarBindL ist(BerEnc oder benc, | |
228 | SnmpVa rBind[] va rBindList) | |
229 | th rows SnmpS tatusExcep tion, Snmp TooBigExce ption { | |
230 | // | |
231 | // Remember: the encod er does ba ckward enc oding | |
232 | // | |
233 | in t encodedV arBindCoun t = 0 ; | |
234 | tr y { | |
235 | benc.ope nSequence( ) ; | |
236 | if (varB indList != null) { | |
237 | for (int i = v arBindList .length - 1 ; i >= 0 ; i--) { | |
238 | SnmpVarBin d bind = v arBindList [i] ; | |
239 | if (bind ! = null) { | |
240 | benc.o penSequenc e() ; | |
241 | encode VarBindVal ue(benc, b ind.value) ; | |
242 | benc.p utOid(bind .oid.longV alue()) ; | |
243 | benc.c loseSequen ce() ; | |
244 | encode dVarBindCo unt++ ; | |
245 | } | |
246 | } | |
247 | } | |
248 | benc.clo seSequence () ; | |
249 | } | |
250 | ca tch(ArrayI ndexOutOfB oundsExcep tion x) { | |
251 | throw ne w SnmpTooB igExceptio n(encodedV arBindCoun t) ; | |
252 | } | |
253 | } | |
254 | ||
255 | /** | |
256 | * For SNMP Runt ime privat e use only . | |
257 | */ | |
258 | void e ncodeVarBi ndValue(Be rEncoder b enc, | |
259 | Sn mpValue v) throws Snm pStatusExc eption { | |
260 | if (v == nul l) { | |
261 | benc.put Null() ; | |
262 | } | |
263 | el se if (v i nstanceof SnmpIpAddr ess) { | |
264 | benc.put OctetStrin g(((SnmpIp Address)v) .byteValue (), SnmpVa lue.IpAddr essTag) ; | |
265 | } | |
266 | el se if (v i nstanceof SnmpCounte r) { | |
267 | benc.put Integer((( SnmpCounte r)v).longV alue(), Sn mpValue.Co unterTag) ; | |
268 | } | |
269 | el se if (v i nstanceof SnmpGauge) { | |
270 | benc.put Integer((( SnmpGauge) v).longVal ue(), Snmp Value.Gaug eTag) ; | |
271 | } | |
272 | el se if (v i nstanceof SnmpTimeti cks) { | |
273 | benc.put Integer((( SnmpTimeti cks)v).lon gValue(), SnmpValue. TimeticksT ag) ; | |
274 | } | |
275 | el se if (v i nstanceof SnmpOpaque ) { | |
276 | benc.put OctetStrin g(((SnmpOp aque)v).by teValue(), SnmpValue .OpaqueTag ) ; | |
277 | } | |
278 | el se if (v i nstanceof SnmpInt) { | |
279 | benc.put Integer((( SnmpInt)v) .intValue( )) ; | |
280 | } | |
281 | el se if (v i nstanceof SnmpString ) { | |
282 | benc.put OctetStrin g(((SnmpSt ring)v).by teValue()) ; | |
283 | } | |
284 | el se if (v i nstanceof SnmpOid) { | |
285 | benc.put Oid(((Snmp Oid)v).lon gValue()) ; | |
286 | } | |
287 | el se if (v i nstanceof SnmpCounte r64) { | |
288 | if (vers ion == snm pVersionOn e) { | |
289 | thro w new Snmp StatusExce ption("Inv alid value for SNMP v1 : " + v ) ; | |
290 | } | |
291 | benc.put Integer((( SnmpCounte r64)v).lon gValue(), SnmpValue. Counter64T ag) ; | |
292 | } | |
293 | el se if (v i nstanceof SnmpNull) { | |
294 | int tag = ((SnmpNu ll)v).getT ag() ; | |
295 | if ((ver sion == sn mpVersionO ne) && (ta g != SnmpV alue.NullT ag)) { | |
296 | thro w new Snmp StatusExce ption("Inv alid value for SNMP v1 : " + v ) ; | |
297 | } | |
298 | if ((ver sion == sn mpVersionT wo) && | |
299 | (tag != SnmpVa lue.NullTa g) && | |
300 | (tag != SnmpVa rBind.errN oSuchObjec tTag) && | |
301 | (tag != SnmpVa rBind.errN oSuchInsta nceTag) && | |
302 | (tag != SnmpVa rBind.errE ndOfMibVie wTag)) { | |
303 | thro w new Snmp StatusExce ption("Inv alid value " + v) ; | |
304 | } | |
305 | benc.put Null(tag) ; | |
306 | } | |
307 | el se { | |
308 | throw ne w SnmpStat usExceptio n("Invalid value " + v) ; | |
309 | } | |
310 | ||
311 | } | |
312 | ||
313 | ||
314 | /** | |
315 | * For SNMP Runt ime privat e use only . | |
316 | */ | |
317 | public SnmpVarBi nd[] decod eVarBindLi st(BerDeco der bdec) | |
318 | th rows BerEx ception { | |
319 | bdec.ope nSequence( ) ; | |
320 | Vector<S nmpVarBind > tmp = ne w Vector<S nmpVarBind >() ; | |
321 | while (b dec.cannot CloseSeque nce()) { | |
322 | Snmp VarBind bi nd = new S nmpVarBind () ; | |
323 | bdec .openSeque nce() ; | |
324 | bind .oid = new SnmpOid(b dec.fetchO id()) ; | |
325 | bind .setSnmpVa lue(decode VarBindVal ue(bdec)) ; | |
326 | bdec .closeSequ ence() ; | |
327 | tmp. addElement (bind) ; | |
328 | } | |
329 | bdec.clo seSequence () ; | |
330 | SnmpVarB ind[] varB indList= n ew SnmpVar Bind[tmp.s ize()] ; | |
331 | tmp.copy Into(varBi ndList); | |
332 | return v arBindList ; | |
333 | } | |
334 | ||
335 | ||
336 | /** | |
337 | * For SNMP Runt ime privat e use only . | |
338 | */ | |
339 | SnmpVa lue decode VarBindVal ue(BerDeco der bdec) | |
340 | th rows BerEx ception { | |
341 | Sn mpValue re sult = nul l ; | |
342 | in t tag = bd ec.getTag( ) ; | |
343 | ||
344 | // bugId 464 1696 : Run timeExcept ions must be transfo rmed in | |
345 | // Ber Exception. | |
346 | sw itch(tag) { | |
347 | ||
348 | // | |
349 | // Simpl e syntax | |
350 | // | |
351 | ca se BerDeco der.Intege rTag : | |
352 | try { | |
353 | resu lt = new S nmpInt(bde c.fetchInt eger()) ; | |
354 | } catch( RuntimeExc eption r) { | |
355 | thro w new BerE xception() ; | |
356 | // B erExceptio n("Can't b uild SnmpI nt from de coded valu e."); | |
357 | } | |
358 | break ; | |
359 | ca se BerDeco der.OctetS tringTag : | |
360 | try { | |
361 | resu lt = new S nmpString( bdec.fetch OctetStrin g()) ; | |
362 | } catch( RuntimeExc eption r) { | |
363 | thro w new BerE xception() ; | |
364 | // B erExceptio n("Can't b uild SnmpS tring from decoded v alue."); | |
365 | } | |
366 | break ; | |
367 | ca se BerDeco der.OidTag : | |
368 | try { | |
369 | resu lt = new S nmpOid(bde c.fetchOid ()) ; | |
370 | } catch( RuntimeExc eption r) { | |
371 | thro w new BerE xception() ; | |
372 | // B erExceptio n("Can't b uild SnmpO id from de coded valu e."); | |
373 | } | |
374 | break ; | |
375 | ca se BerDeco der.NullTa g : | |
376 | bdec.fet chNull() ; | |
377 | try { | |
378 | resu lt = new S nmpNull() ; | |
379 | } catch( RuntimeExc eption r) { | |
380 | thro w new BerE xception() ; | |
381 | // B erExceptio n("Can't b uild SnmpN ull from d ecoded val ue."); | |
382 | } | |
383 | break ; | |
384 | ||
385 | // | |
386 | // Appli cation syn tax | |
387 | // | |
388 | ca se SnmpVal ue.IpAddre ssTag : | |
389 | try { | |
390 | resu lt = new S nmpIpAddre ss(bdec.fe tchOctetSt ring(tag)) ; | |
391 | } catch (RuntimeEx ception r) { | |
392 | thro w new Ber Exception( ); | |
393 | // Ber Exception( "Can't bui ld SnmpIpA ddress fro m decoded value."); | |
394 | } | |
395 | break ; | |
396 | ca se SnmpVal ue.Counter Tag : | |
397 | try { | |
398 | resu lt = new S nmpCounter (bdec.fetc hIntegerAs Long(tag)) ; | |
399 | } catch( RuntimeExc eption r) { | |
400 | thro w new BerE xception() ; | |
401 | // B erExceptio n("Can't b uild SnmpC ounter fro m decoded value."); | |
402 | } | |
403 | break ; | |
404 | ca se SnmpVal ue.GaugeTa g : | |
405 | try { | |
406 | resu lt = new S nmpGauge(b dec.fetchI ntegerAsLo ng(tag)) ; | |
407 | } catch( RuntimeExc eption r) { | |
408 | thro w new BerE xception() ; | |
409 | // B erExceptio n("Can't b uild SnmpG auge from decoded va lue."); | |
410 | } | |
411 | break ; | |
412 | ca se SnmpVal ue.Timetic ksTag : | |
413 | try { | |
414 | resu lt = new S nmpTimetic ks(bdec.fe tchInteger AsLong(tag )) ; | |
415 | } catch( RuntimeExc eption r) { | |
416 | thro w new BerE xception() ; | |
417 | // BerE xception(" Can't buil d SnmpTime ticks from decoded v alue."); | |
418 | } | |
419 | break ; | |
420 | ca se SnmpVal ue.OpaqueT ag : | |
421 | try { | |
422 | resu lt = new S nmpOpaque( bdec.fetch OctetStrin g(tag)) ; | |
423 | } catch( RuntimeExc eption r) { | |
424 | thro w new BerE xception() ; | |
425 | // B erExceptio n("Can't b uild SnmpO paque from decoded v alue."); | |
426 | } | |
427 | break ; | |
428 | ||
429 | // | |
430 | // V2 sy ntaxes | |
431 | // | |
432 | ca se SnmpVal ue.Counter 64Tag : | |
433 | if (vers ion == snm pVersionOn e) { | |
434 | thro w new BerE xception(B erExceptio n.BAD_VERS ION) ; | |
435 | } | |
436 | try { | |
437 | resu lt = new S nmpCounter 64(bdec.fe tchInteger AsLong(tag )) ; | |
438 | } catch( RuntimeExc eption r) { | |
439 | thro w new BerE xception() ; | |
440 | // BerE xception(" Can't buil d SnmpCoun ter64 from decoded v alue."); | |
441 | } | |
442 | break ; | |
443 | ||
444 | ca se SnmpVar Bind.errNo SuchObject Tag : | |
445 | if (vers ion == snm pVersionOn e) { | |
446 | thro w new BerE xception(B erExceptio n.BAD_VERS ION) ; | |
447 | } | |
448 | bdec.fet chNull(tag ) ; | |
449 | result = SnmpVarBi nd.noSuchO bject ; | |
450 | break ; | |
451 | ||
452 | ca se SnmpVar Bind.errNo SuchInstan ceTag : | |
453 | if (vers ion == snm pVersionOn e) { | |
454 | thro w new BerE xception(B erExceptio n.BAD_VERS ION) ; | |
455 | } | |
456 | bdec.fet chNull(tag ) ; | |
457 | result = SnmpVarBi nd.noSuchI nstance ; | |
458 | break ; | |
459 | ||
460 | ca se SnmpVar Bind.errEn dOfMibView Tag : | |
461 | if (vers ion == snm pVersionOn e) { | |
462 | thro w new BerE xception(B erExceptio n.BAD_VERS ION) ; | |
463 | } | |
464 | bdec.fet chNull(tag ) ; | |
465 | result = SnmpVarBi nd.endOfMi bView ; | |
466 | break ; | |
467 | ||
468 | de fault: | |
469 | throw ne w BerExcep tion() ; | |
470 | ||
471 | } | |
472 | ||
473 | re turn resul t ; | |
474 | } | |
475 | ||
476 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.