1 // NAME 2 // $RCSfile: AsnDecoderv1.java,v $ 3 // DESCRIPTION 4 // [given below in javadoc format] 5 // DELTA 6 // $Revision: 3.3 $ 7 // CREATED 8 // $Date: 2006/02/09 14:16:36 $ 9 // COPYRIGHT 10 // Westhawk Ltd 11 // TO DO 12 // 13 14 15 /* 16 * Copyright (C) 1996 - 2006 by Westhawk Ltd 17 * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a> 18 * 19 * Permission to use, copy, modify, and distribute this software 20 * for any purpose and without fee is hereby granted, provided 21 * that the above copyright notices appear in all copies and that 22 * both the copyright notice and this permission notice appear in 23 * supporting documentation. 24 * This software is provided "as is" without express or implied 25 * warranty. 26 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a> 27 */ 28 29 package uk.co.westhawk.snmp.stack; 30 31 /*- 32 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 33 * SNMP Java Client 34 * ჻჻჻჻჻჻ 35 * Copyright 2023 MetricsHub, Westhawk 36 * ჻჻჻჻჻჻ 37 * This program is free software: you can redistribute it and/or modify 38 * it under the terms of the GNU Lesser General Public License as 39 * published by the Free Software Foundation, either version 3 of the 40 * License, or (at your option) any later version. 41 * 42 * This program is distributed in the hope that it will be useful, 43 * but WITHOUT ANY WARRANTY; without even the implied warranty of 44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 45 * GNU General Lesser Public License for more details. 46 * 47 * You should have received a copy of the GNU General Lesser Public 48 * License along with this program. If not, see 49 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 50 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 51 */ 52 53 import uk.co.westhawk.snmp.util.*; 54 import java.io.*; 55 import java.util.*; 56 57 /** 58 * This class contains the v1 specific methods to decode bytes into a Pdu. 59 * We split the original class AsnDecoder into four classes. 60 * 61 * @since 4_14 62 * @author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a> 63 * @version $Revision: 3.3 $ $Date: 2006/02/09 14:16:36 $ 64 */ 65 class AsnDecoderv1 extends AsnDecoderBase { 66 private static final String version_id = "@(#)$Id: AsnDecoderv1.java,v 3.3 2006/02/09 14:16:36 birgit Exp $ Copyright Westhawk Ltd"; 67 68 /** 69 * This method creates an AsnPduSequence or an AsnTrapPduv1Sequence out of 70 * the characters of the InputStream for v1. 71 * 72 * @see AbstractSnmpContext#run 73 * @see SnmpContext#processIncomingResponse 74 * @see SnmpContext#processIncomingPdu 75 */ 76 AsnSequence DecodeSNMP(InputStream in, String community) 77 throws IOException, DecodingException { 78 AsnSequence asnTopSeq = getAsnSequence(in); 79 int snmpVersion = getSNMPVersion(asnTopSeq); 80 if (snmpVersion != SnmpConstants.SNMP_VERSION_1) { 81 String str = SnmpUtilities.getSnmpVersionString(snmpVersion); 82 String msg = "Wrong SNMP version: expected SNMPv1, received " 83 + str; 84 throw new DecodingException(msg); 85 } 86 String comm = getCommunity(asnTopSeq); 87 if (comm.equals(community) == false) { 88 String msg = "Wrong community: expected " 89 + community + ", received " + comm; 90 throw new DecodingException(msg); 91 } 92 93 // The message is either a 'normal' PDU or a Trap v1 PDU. 94 AsnSequence seqPdu = null; 95 seqPdu = (AsnPduSequence) asnTopSeq.findPdu(); 96 if (seqPdu == null) { 97 seqPdu = (AsnTrapPduv1Sequence) asnTopSeq.findTrapPduv1(); 98 } 99 return seqPdu; 100 } 101 102 }