View Javadoc
1   // NAME
2   //      $RCSfile: ResponsePdu.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 3.6 $
7   // CREATED
8   //      $Date: 2006/11/30 14:45:50 $
9   // COPYRIGHT
10  //      Westhawk Ltd
11  // TO DO
12  //
13  
14  /*
15   * Copyright (C) 2005 - 2006 by Westhawk Ltd
16   * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
17   *
18   * Permission to use, copy, modify, and distribute this software
19   * for any purpose and without fee is hereby granted, provided
20   * that the above copyright notices appear in all copies and that
21   * both the copyright notice and this permission notice appear in
22   * supporting documentation.
23   * This software is provided "as is" without express or implied
24   * warranty.
25   * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
26   */
27  
28  package uk.co.westhawk.snmp.stack;
29  
30  /*-
31   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32   * SNMP Java Client
33   * ჻჻჻჻჻჻
34   * Copyright 2023 MetricsHub, Westhawk
35   * ჻჻჻჻჻჻
36   * This program is free software: you can redistribute it and/or modify
37   * it under the terms of the GNU Lesser General Public License as
38   * published by the Free Software Foundation, either version 3 of the
39   * License, or (at your option) any later version.
40   *
41   * This program is distributed in the hope that it will be useful,
42   * but WITHOUT ANY WARRANTY; without even the implied warranty of
43   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44   * GNU General Lesser Public License for more details.
45   *
46   * You should have received a copy of the GNU General Lesser Public
47   * License along with this program.  If not, see
48   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50   */
51  
52  /**
53   * This class represents the ASN SNMP Response PDU object.
54   * This class should be used when responding to an incoming request 
55   * via a ListeningContext. Note that you should use the port of the
56   * RequestPduEvent (getHostPort()) when creating a SnmpContext.
57   *
58   * <p>
59   * This class is <em>not</em> used when request are sent out by the
60   * stack and a response is received. In that case the OIDs of the
61   * response are integrated into the original request PDU. 
62   * </p>
63   *
64   * <p>
65   * For SNMPv3: The sender of a response PDU acts as the authoritative engine.
66   * </p>
67   *
68   * @see ListeningContext
69   * @see uk.co.westhawk.snmp.event.RequestPduEvent
70   * @see uk.co.westhawk.snmp.event.RequestPduEvent#getHostPort()
71   *
72   * @since 4_14
73   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
74   * @version $Revision: 3.6 $ $Date: 2006/11/30 14:45:50 $
75   */
76  public class ResponsePdu extends Pdu {
77      private static final String version_id = "@(#)$Id: ResponsePdu.java,v 3.6 2006/11/30 14:45:50 birgit Exp $ Copyright Westhawk Ltd";
78  
79      /**
80       * Constructor.
81       * The requestPdu is used to copy the necessary IDs to this PDU.
82       *
83       * @param con        The context of the PDU
84       * @param requestPdu The original Request PDU
85       */
86      public ResponsePdu(SnmpContextBasisFace con, Pdu requestPdu) {
87          super(con);
88          setMsgType(AsnObject.GET_RSP_MSG);
89          req_id = requestPdu.req_id;
90          snmpv3MsgId = requestPdu.snmpv3MsgId;
91      }
92  
93      /**
94       * Sets the error status of this PDU. This indicates that an exception
95       * has occurred while processing the original request.
96       *
97       * @see SnmpConstants#SNMP_ERR_NOERROR
98       * @see SnmpConstants#SNMP_ERR_TOOBIG
99       * @see SnmpConstants#SNMP_ERR_NOSUCHNAME
100      * @see SnmpConstants#SNMP_ERR_BADVALUE
101      * @see SnmpConstants#SNMP_ERR_READONLY
102      * @see SnmpConstants#SNMP_ERR_GENERR
103      * @see SnmpConstants#SNMP_ERR_NOACCESS
104      * @see SnmpConstants#SNMP_ERR_WRONGTYPE
105      * @see SnmpConstants#SNMP_ERR_WRONGLENGTH
106      * @see SnmpConstants#SNMP_ERR_WRONGENCODING
107      * @see SnmpConstants#SNMP_ERR_WRONGVALUE
108      * @see SnmpConstants#SNMP_ERR_NOCREATION
109      * @see SnmpConstants#SNMP_ERR_INCONSISTENTVALUE
110      * @see SnmpConstants#SNMP_ERR_RESOURCEUNAVAILABLE
111      * @see SnmpConstants#SNMP_ERR_COMMITFAILED
112      * @see SnmpConstants#SNMP_ERR_UNDOFAILED
113      * @see SnmpConstants#SNMP_ERR_AUTHORIZATIONERR
114      * @see SnmpConstants#SNMP_ERR_NOTWRITABLE
115      * @see SnmpConstants#SNMP_ERR_INCONSISTENTNAME
116      *
117      * @since 5_2
118      */
119     public void setErrorStatus(int errorStatus) {
120         errstat = errorStatus;
121     }
122 
123     /**
124      * Sets the error index of this PDU. When the error status is not
125      * SNMP_ERR_NOERROR, it indicates the index of the variable in the
126      * varbind list that caused the exception.
127      *
128      * @since 5_2
129      */
130     public void setErrorIndex(int errorIndex) {
131         errind = errorIndex;
132     }
133 
134     /**
135      * The Response PDU does not get a response back. So it should be sent once.
136      */
137     void transmit() {
138         transmit(false);
139     }
140 
141     /**
142      * Returns the string representation of this object.
143      *
144      * @return The string of the PDU
145      */
146     public String toString() {
147         return super.toString(true);
148     }
149 
150     /**
151      * Has no meaning, since there is not response.
152      */
153     protected void new_value(int n, varbind res) {
154     }
155 
156     /**
157      * Has no meaning, since there is not response.
158      */
159     protected void tell_them() {
160     }
161 
162     /**
163      * Returns that this type of PDU is <em>not</em> expecting a response.
164      * This method is used in AbstractSnmpContext to help determine whether
165      * or not to start a thread that listens for a response when sending this
166      * PDU.
167      * The default is <em>false</em>.
168      *
169      * @return true if a response is expected, false if not.
170      */
171     protected boolean isExpectingResponse() {
172         return false;
173     }
174 
175 }