/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// XXX: things to do: use SnmpOid rather than `instance' for future
// evolutions.
// XXX: Maybe use hashlists rather than vectors for entries?
// => in that case, the key should be SnmpOid.toString()
//
/**
* This class is used to register varbinds from a SNMP varbind list with
* the SnmpMibNode responsible for handling the requests concerning that
* varbind.
* This class holds a hashtable of Handler nodes, whith the involved
* SnmpMibNode as a key.
* When the involved SnmpMibNode is a group, the sublist of varbind is
* directly stored in the Handler node.
* When the involved SnmpMibNode is a table, the sublist is stored in a
* sorted array indexed by the OID of the entry involved.
*/
final class SnmpRequestTree {
// Constructor:
// @param req The SnmpMibRequest that will be segmented in this
// tree. It holds the original varbind vector passed
// by the SnmpSubRequestHandler to this MIB. This
// varbind vector is used to retrieve the "real"
// position of a varbind in the vector. There is no other easy
// way to do this - since as a result of the segmentation the
// original positions will be lost.
// @param creationflag indicates whether the operation involved
// allows for entry creation (ie: it is a SET request).
// @param pdutype indicates the type of the request PDU as defined
// in SnmpDefinitions
//
this.creationflag = creationflag;
}
throws SnmpStatusException {
final int errorCode = errorStatus;
return errorCode;
int mappedErrorCode = errorCode;
// Now take care of V2 errorCodes that can be stored
// in the varbind itself:
// noSuchObject => notWritable
// noSuchInstance => notWritable
return mappedErrorCode;
}
throws SnmpStatusException {
final int errorCode = errorStatus;
return errorCode;
int mappedErrorCode = errorCode;
// Now take care of V2 errorCodes that can be stored
// in the varbind itself:
if (errorCode ==
// noSuchObject => noSuchObject
else if (errorCode ==
// noSuchInstance => noSuchInstance
// Now we're going to try to transform every other
// global code in either noSuchInstance or noSuchObject,
// so that the get can return a partial result.
//
// Only noSuchInstance or noSuchObject can be stored
// in the varbind itself.
//
// According to RFC 1905: noAccess is emitted when the
// the access is denied because it is not in the MIB view...
//
else if (errorCode ==
// noAccess => noSuchInstance
// According to RFC 1905: (my interpretation because it is not
// really clear) The specified variable name exists - but the
// variable does not exists and cannot be created under the
// present circumstances (probably because the request specifies
// value of some other variable in the MIB prevents the creation)
//
// Note that this error should never be raised in a GET context
// but who knows?
//
// inconsistentName => noSuchInstance
// All the errors comprised between snmpRspWrongType and
// snmpRspInconsistentValue concern values: so we're going
// to assume the OID was correct, and reply with noSuchInstance.
//
// Note that this error should never be raised in a GET context
// but who knows?
//
// We're going to assume the OID was correct, and reply
// with noSuchInstance.
//
// For all other errors but genErr, we're going to reply with
// noSuchObject
//
// Only genErr will abort the GET and be returned as global
// error.
//
return mappedErrorCode;
}
//-------------------------------------------------------------------
// This class is a package implementation of the enumeration of
// SnmSubRequest associated with an Handler node.
//-------------------------------------------------------------------
handler = h;
size = h.getSubReqCount();
}
public boolean hasMoreElements() {
}
if (iter == 0) {
iter++;
}
}
iter ++;
entry++;
return result;
}
}
//-------------------------------------------------------------------
// This class is a package implementation of the SnmpMibSubRequest
// interface. It can only be instantiated by SnmpRequestTree.
//-------------------------------------------------------------------
this.getnextflag = getnextflag;
}
final private int version;
final private boolean isnew;
final private boolean getnextflag;
// -------------------------------------------------------------
// Implements the method defined in SnmpMibRequest interface.
// See SnmpMibRequest for the java doc.
// -------------------------------------------------------------
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibRequest interface.
// See SnmpMibRequest for the java doc.
// -------------------------------------------------------------
return varbinds;
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibRequest interface.
// See SnmpMibRequest for the java doc.
// -------------------------------------------------------------
public final int getSize() {
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibRequest interface.
// See SnmpMibRequest for the java doc.
// -------------------------------------------------------------
// XXX not sure we must also add the varbind in the global
// request? or whether we should raise an exception:
// in principle, this method should not be called!
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibSubRequest interface.
// See SnmpMibSubRequest for the java doc.
// -------------------------------------------------------------
public boolean isNewEntry() {
return isnew;
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibSubRequest interface.
// See SnmpMibSubRequest for the java doc.
// -------------------------------------------------------------
return entryoid;
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibRequest interface.
// See SnmpMibRequest for the java doc.
// -------------------------------------------------------------
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibRequest interface.
// See SnmpMibRequest for the java doc.
// -------------------------------------------------------------
// -------------------------------------------------------------
// Implements the method defined in SnmpMibSubRequest interface.
// See SnmpMibSubRequest for the java doc.
// -------------------------------------------------------------
throws SnmpStatusException {
// The index in the exception must correspond to
// the SNMP index ...
//
throw exception;
// If we're doing a getnext ==> endOfMibView
if (getnextflag) {
return;
}
version);
// Now take care of V2 errorCodes that can be stored
// in the varbind itself:
if (errorCode ==
// noSuchObject => noSuchObject
else if (errorCode ==
// noSuchInstance => noSuchInstance
else
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibSubRequest interface.
// See SnmpMibSubRequest for the java doc.
// -------------------------------------------------------------
throws SnmpStatusException {
// The index in the exception must correspond to
// the SNMP index ...
//
// Although the first pass of check() did not fail,
// the set() phase could not be carried out correctly.
// Since we don't know how to make an "undo", and some
// assignation may already have been performed, we're going
// to throw an snmpRspUndoFailed.
//
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibSubRequest interface.
// See SnmpMibSubRequest for the java doc.
// -------------------------------------------------------------
throws SnmpStatusException {
// The index in the exception must correspond to
// the SNMP index ...
//
// We throw the exception in order to abort the SET operation
// in an atomic way.
version);
if (errorCode != mappedErrorCode)
throw new
else
}
// -------------------------------------------------------------
// Implements the method defined in SnmpMibRequest interface.
// See SnmpMibRequest for the java doc.
// -------------------------------------------------------------
public int getVersion() {
return version;
}
return statusvb;
}
}
public int getRequestPduVersion() {
return global.getRequestPduVersion();
}
}
return global.getPrincipal();
}
public int getSecurityLevel() {
return global.getSecurityLevel();
}
public int getSecurityModel() {
return global.getSecurityModel();
}
public byte[] getContextName() {
return global.getContextName();
}
public byte[] getAccessContextName() {
return global.getAccessContextName();
}
}
//-------------------------------------------------------------------
// This class implements a node in the SnmpRequestTree.
// It stores:
// o The SnmpMibNode involved (key)
// o The sublist of varbind directly handled by this node
// o A vector of sublists concerning the entries (existing or not)
// of the SnmpMIbNode (when it is a table).
//-------------------------------------------------------------------
static final class Handler {
// List entryoids; // Sorted array of entry oids
// List entrylists; // Sorted array of entry lists
// List isentrynew; // Sorted array of booleans
}
/**
* Adds a varbind in this node sublist.
*/
}
/**
* register an entry for the given oid at the given position with
* the given sublist.
*/
@SuppressWarnings("unchecked")
// We need this because of new Vector[n] instead of
// new Vector<SnmpVarBind>[n], which is illegal.
// Vectors are null: Allocate new vectors
isentrynew = new boolean[Delta];
pos = 0;
// Vectors must be enlarged
// Save old vectors
boolean[] oldn = isentrynew;
// Allocate larger vectors
isentrynew = new boolean[entrysize];
// Check pos validity
// Copy original vectors up to `pos'
if (l1 > 0) {
0,l1);
0,l1);
0,l1);
0,l1);
}
// Copy original vectors from `pos' to end, leaving
// an empty room at `pos' in the new vectors.
if (l2 > 0) {
}
} else if (pos < entrycount) {
// Vectors are large enough to accomodate one additional
// entry.
//
// Shift vectors, making an empty room at `pos'
}
// Fill the gap at `pos'
entrylists[pos] = v;
entrycount++;
}
throws SnmpStatusException {
// entryoids = new ArrayList();
// entrylists = new ArrayList();
// isentrynew = new ArrayList();
v = new Vector<SnmpVarBind>();
// entryoids.add(entryoid);
// entrylists.add(v);
// isentrynew.add(new Boolean(isnew));
} else {
// int pos = findOid(entryoids,entryoid);
// int pos = findOid(entryoids,entrycount,entryoid);
final int pos =
v = entrylists[pos];
} else {
// if (pos == -1 || pos >= entryoids.size() ) {
// if (pos == -1 || pos >= entrycount ) {
// pos = getInsertionPoint(entryoids,entryoid);
// pos = getInsertionPoint(entryoids,entrycount,entryoid);
v = new Vector<SnmpVarBind>();
// entryoids.add(pos,entryoid);
// entrylists.add(pos,v);
// isentrynew.add(pos,new Boolean(isnew));
}
// } else v = (Vector) entrylists.get(pos);
// } else v = entrylists[pos];
throw new SnmpStatusException(
}
}
}
// We do not include the status variable in the varbind,
// because we're going to set it separately...
//
v.addElement(varbind);
}
public int getSubReqCount() {
int count = 0;
// if (entryoids != null) count += entryoids.size();
return count;
}
return sublist;
}
// return findOid(entryoids,entryoid);
}
// if (pos == -1 || pos >= entryoids.size() ) return null;
// return (SnmpOid) entryoids.get(pos);
}
// if (pos == -1 || pos >= entryoids.size() ) return false;
// return ((Boolean)isentrynew.get(pos)).booleanValue();
return isentrynew[pos];
}
// if (pos == -1 || pos >= entryoids.size() ) return false;
// return ((Boolean)isentrynew.get(pos)).booleanValue();
}
// if (pos == -1 || pos >= entrylists.size() ) return null;
// return (Vector) entrylists.get(pos);
return entrylists[pos];
}
// return entryoids.iterator();
}
public int getEntryCount() {
// return entryoids.size();
return entrycount;
}
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Public interface
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Returns the contextual object containing user-data allocated
// through the SnmpUserDataFactory for this request.
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Tells whether creation of new entries is allowed with respect
//-------------------------------------------------------------------
public boolean isCreationAllowed() {
return creationflag;
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
public boolean isSetRequest() {
return setreqflag;
}
//-------------------------------------------------------------------
// Returns the protocol version in which the original request is
// evaluated.
//-------------------------------------------------------------------
public int getVersion() {
return version;
}
//-------------------------------------------------------------------
// Returns the actual protocol version of the request PDU.
//-------------------------------------------------------------------
public int getRequestPduVersion() {
return request.getRequestPduVersion();
}
//-------------------------------------------------------------------
// Returns the SnmpMibNode associated with the given handler
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// Indicates the depth of the arc in the OID that identifies the
// SnmpMibNode associated with the given handler
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// returns an enumeration of the SnmpMibSubRequest's to be invoked on
// the SnmpMibNode associated with a given Handler node.
// If this node is a group, there will be a single subrequest.
// If it is a table, there will be one subrequest per entry involved.
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// returns an enumeration of the Handlers stored in the Hashtable.
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// adds a varbind to a handler node sublist
//-------------------------------------------------------------------
throws SnmpStatusException {
}
//-------------------------------------------------------------------
// adds an entry varbind to a handler node sublist
//-------------------------------------------------------------------
throws SnmpStatusException {
}
//-------------------------------------------------------------------
// adds an entry varbind to a handler node sublist - specifying the
// varbind which holds the row status
//-------------------------------------------------------------------
throws SnmpStatusException {
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Protected interface
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Type of the request (see SnmpDefinitions)
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// We deal with a GET-NEXT request
//-------------------------------------------------------------------
void setGetNextFlag() {
getnextflag = true;
}
//-------------------------------------------------------------------
// Tell whether creation is allowed.
//-------------------------------------------------------------------
creationflag = flag;
}
//-------------------------------------------------------------------
// Returns the subrequest handled by the SnmpMibNode itself
// (in principle, only for Groups)
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// Returns the subrequest associated with the entry identified by
// the given entry (only for tables)
//-------------------------------------------------------------------
return new SnmpMibSubRequestImpl(request,
}
//-------------------------------------------------------------------
// Returns the subrequest associated with the entry identified by
// the given entry (only for tables). The `entry' parameter is an
// index relative to the position of the entry in the handler sublist.
//-------------------------------------------------------------------
return new
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Private section
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// stores a handler node in the Hashtable
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// finds a handler node in the Hashtable
//-------------------------------------------------------------------
}
//-------------------------------------------------------------------
// Search for the given oid in `oids'. If none is found, returns -1
// otherwise, returns the index at which the oid is located.
//-------------------------------------------------------------------
int low= 0;
//System.out.println("Try to retrieve: " + oid.toString());
//System.out.println("Compare with" + pos.toString());
// never know ...we might find something ...
//
if (comp == 0)
return curr;
return curr;
}
if (comp > 0) {
} else {
}
}
return -1;
}
//-------------------------------------------------------------------
// Return the index at which the given oid should be inserted in the
// `oids' array.
//-------------------------------------------------------------------
int low= 0;
// never know ...we might find something ...
//
// In the calling method we will have to check for this case...
// if (comp == 0)
// return -1;
// Returning curr instead of -1 avoids having to call
// findOid() first and getInsertionPoint() afterwards.
// We can simply call getInsertionPoint() and then checks whether
// there's an OID at the returned position which equals the
// given OID.
if (comp == 0)
return curr;
if (comp>0) {
} else {
}
}
return curr;
}
//-------------------------------------------------------------------
// adds a varbind in a handler node sublist
//-------------------------------------------------------------------
throws SnmpStatusException {
SnmpRequestTree.class.getName(),
"registerNode", "meta-node is null!");
return;
}
SnmpRequestTree.class.getName(),
"registerNode", "varbind is null!");
return ;
}
// retrieve the handler node associated with the given meta,
// if any
// If no handler node was found for that meta, create one.
// if (isDebugOn())
// debug("registerNode", "adding node for " +
// varbind.oid.toString());
}
// else {
// if (isDebugOn())
// debug("registerNode","found node for " +
// varbind.oid.toString());
// }
// Adds the varbind in the handler node's sublist.
else
return ;
}
//-------------------------------------------------------------------
// private variables
//-------------------------------------------------------------------
// Hashtable of Handler objects
// creation of entries
// creation of entries
// in SnmpDefinitions
}