use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibGroup method findHandlingNode.
// -------------------------------------------------------------------
// see comments in SnmpMibNode
// -------------------------------------------------------------------
@Override
void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) throws SnmpStatusException {
int length = oid.length;
if (handlers == null)
throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr);
final Object data = handlers.getUserData();
if (depth >= length) {
// Nothing is left... the oid is not valid
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
long arc = oid[depth];
if (isNestedArc(arc)) {
// This arc leads to a subgroup: delegates the search to the
// method defined in SnmpMibOid
super.findHandlingNode(varbind, oid, depth, handlers);
} else if (isTable(arc)) {
// This arc leads to a table: forward the search to the table.
// Gets the table
SnmpMibTable table = getTable(arc);
// Forward the search to the table
table.findHandlingNode(varbind, oid, depth + 1, handlers);
} else {
// If it's not a variable, throws an exception
validateVarId(arc, data);
// The trailing .0 is missing in the OID
if (depth + 2 > length) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// a single trailing .0)
if (depth + 2 < length) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// The last trailing arc is not .0
if (oid[depth + 1] != 0L) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// It's one of our variable, register this node.
handlers.add(this, depth, varbind);
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibGroup method findNextHandlingNode.
// -------------------------------------------------------------------
// See comments in SnmpMibNode.
// -------------------------------------------------------------------
@Override
long[] findNextHandlingNode(SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, AcmChecker checker) throws SnmpStatusException {
int length = oid.length;
SnmpMibNode node = null;
if (handlers == null) {
//
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
final Object data = handlers.getUserData();
final int pduVersion = handlers.getRequestPduVersion();
// arc to -1 would work too.
if (pos >= length)
return super.findNextHandlingNode(varbind, oid, pos, depth, handlers, checker);
// Ok, we've got the arc.
long arc = oid[pos];
long[] result = null;
// We have a recursive logic. Should we have a loop instead?
try {
if (isTable(arc)) {
// If the arc identifies a table, then we need to forward
// the search to the table.
// Gets the table identified by `arc'
SnmpMibTable table = getTable(arc);
// Forward to the table
checker.add(depth, arc);
try {
result = table.findNextHandlingNode(varbind, oid, pos + 1, depth + 1, handlers, checker);
} catch (SnmpStatusException ex) {
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
} finally {
checker.remove(depth);
}
// Build up the leaf OID
result[depth] = arc;
return result;
} else if (isReadable(arc)) {
if (pos == (length - 1)) {
// The end of the OID is reached, so we return the leaf
// corresponding to the variable identified by `arc'
// Build up the OID
// result = new SnmpOid(0);
// result.insert((int)arc);
result = new long[depth + 2];
result[depth + 1] = 0L;
result[depth] = arc;
checker.add(depth, result, depth, 2);
try {
checker.checkCurrentOid();
} catch (SnmpStatusException e) {
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
} finally {
checker.remove(depth, 2);
}
// Registers this node
handlers.add(this, depth, varbind);
return result;
}
// The end of the OID is not yet reached, so we must return
// the next leaf following the variable identified by `arc'.
// We cannot return the variable because whatever follows in
// the OID will be greater or equals to 0, and 0 identifies
// the variable itself - so we have indeed to return the
// next object.
// So we do nothing, because this case is handled at the
// end of the if ... else if ... else ... block.
} else if (isNestedArc(arc)) {
// Now if the arc leads to a subgroup, we delegate the
// search to the child, just as done in SnmpMibNode.
//
// get the child ( = nested arc node).
//
final SnmpMibNode child = getChild(arc);
if (child != null) {
checker.add(depth, arc);
try {
result = child.findNextHandlingNode(varbind, oid, pos + 1, depth + 1, handlers, checker);
result[depth] = arc;
return result;
} finally {
checker.remove(depth);
}
}
}
//
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
} catch (SnmpStatusException e) {
// We didn't find anything at the given arc, so we're going
// to try with the next valid arc
//
long[] newOid = new long[1];
newOid[0] = getNextVarId(arc, data, pduVersion);
return findNextHandlingNode(varbind, newOid, 0, depth, handlers, checker);
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibOid method check.
/**
* Generic handling of the <CODE>check</CODE> operation.
*
* <p> This method should be overridden in subclasses.
* <p>
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException The default implementation (if not
* overridden) is to generate a SnmpStatusException.
*/
@Override
public void check(SnmpMibSubRequest req, int depth) throws SnmpStatusException {
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
SnmpVarBind var = e.nextElement();
SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
req.registerCheckException(var, x);
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method findHandlingNode.
// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode.
//
// ---------------------------------------------------------------------
@Override
final synchronized void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) throws SnmpStatusException {
final int length = oid.length;
if (handlers == null)
throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr);
if (depth >= length)
throw new SnmpStatusException(SnmpStatusException.noAccess);
if (oid[depth] != nodeId)
throw new SnmpStatusException(SnmpStatusException.noAccess);
if (depth + 2 >= length)
throw new SnmpStatusException(SnmpStatusException.noAccess);
// Checks that the oid is valid
// validateOid(oid,depth);
// Gets the part of the OID that identifies the entry
final SnmpOid entryoid = new SnmpEntryOid(oid, depth + 2);
// Finds the entry: false means that the entry does not exists
final Object data = handlers.getUserData();
final boolean hasEntry = contains(entryoid, data);
// We know that the entry does not exists if (isentry == false).
if (!hasEntry) {
if (!handlers.isCreationAllowed()) {
// we're not doing a set
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
} else if (!isCreationEnabled())
// we're doing a set but creation is disabled.
throw new SnmpStatusException(SnmpStatusException.snmpRspNoAccess);
}
final long var = oid[depth + 1];
// Validate the entry id
if (hasEntry) {
// The entry already exists - validate the id
validateVarEntryId(entryoid, var, data);
}
//
if (handlers.isSetRequest() && isRowStatus(entryoid, var, data))
// We only try to identify the RowStatus for SET operations
//
handlers.add(this, depth, entryoid, varbind, (!hasEntry), varbind);
else
handlers.add(this, depth, entryoid, varbind, (!hasEntry));
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpStandardObjectServer method check.
/**
* Generic handling of the <CODE>check</CODE> operation.
* <p> The default implementation of this method is to loop over the
* varbind list associated with the sub-request and to call
* <CODE>check(var.value, var.oid.getOidArc(depth), data);</CODE>
* <pre>
* public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
* int depth)
* throws SnmpStatusException {
*
* final Object data = req.getUserData();
*
* for (Enumeration e= req.getElements(); e.hasMoreElements();) {
*
* final SnmpVarBind var= (SnmpVarBind) e.nextElement();
*
* try {
* // This method will generate a SnmpStatusException
* // if `depth' is out of bounds.
* //
* final long id = var.oid.getOidArc(depth);
* meta.check(var.value, id, data);
* } catch(SnmpStatusException x) {
* req.registerCheckException(var,x);
* }
* }
* }
* </pre>
* <p> You can override this method if you need to implement some
* specific policies for minimizing the accesses made to some remote
* underlying resources, or if you need to implement some consistency
* checks between the different values provided in the varbind list.
* <p>
*
* @param meta A pointer to the generated meta-data object which
* implements the <code>SnmpStandardMetaServer</code>
* interface.
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException An error occurred while accessing
* the MIB node.
*/
public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final Object data = req.getUserData();
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
final SnmpVarBind var = e.nextElement();
try {
// This method will generate a SnmpStatusException
// if `depth' is out of bounds.
//
final long id = var.oid.getOidArc(depth);
meta.check(var.value, id, data);
} catch (SnmpStatusException x) {
req.registerCheckException(var, x);
}
}
}
Aggregations