📄 snmprequesttree.java
字号:
// the SNMP index ... // if (version == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(exception, getVarIndex(var)+1); // 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. // throw new SnmpStatusException(SnmpDefinitions.snmpRspUndoFailed, getVarIndex(var)+1); } // ------------------------------------------------------------- // Implements the method defined in SnmpMibSubRequest interface. // See SnmpMibSubRequest for the java doc. // ------------------------------------------------------------- public void registerCheckException(SnmpVarBind var, SnmpStatusException exception) 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. final int errorCode = exception.getStatus(); final int mappedErrorCode = mapSetException(errorCode, version); if (errorCode != mappedErrorCode) throw new SnmpStatusException(mappedErrorCode, getVarIndex(var)+1); else throw new SnmpStatusException(exception, getVarIndex(var)+1); } // ------------------------------------------------------------- // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- public int getVersion() { return version; } public SnmpVarBind getRowStatusVarBind() { return statusvb; } public SnmpPdu getPdu() { return global.getPdu(); } public int getRequestPduVersion() { return global.getRequestPduVersion(); } public SnmpEngine getEngine() { return global.getEngine(); } public String getPrincipal() { 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 { SnmpMibNode meta; // The meta which handles the sublist. int depth; // The depth of the meta node. Vector sublist; // The sublist of varbinds to be handled. // List entryoids; // Sorted array of entry oids // List entrylists; // Sorted array of entry lists // List isentrynew; // Sorted array of booleans SnmpOid[] entryoids = null; // Sorted array of entry oids Vector[] entrylists = null; // Sorted array of entry lists boolean[] isentrynew = null; // Sorted array of booleans SnmpVarBind[] rowstatus = null; // RowStatus varbind, if any int entrycount = 0; int entrysize = 0; final int type; // request PDU type as defined in SnmpDefinitions final private static int Delta = 10; public Handler(int pduType) { this.type = pduType; } /** * Adds a varbind in this node sublist. */ public void addVarbind(SnmpVarBind varbind) { if (sublist == null) sublist = new Vector(); sublist.addElement(varbind); } /** * register an entry for the given oid at the given position with * the given sublist. */ void add(int pos,SnmpOid oid, Vector v, boolean isnew, SnmpVarBind statusvb) { if (entryoids == null) { // Vectors are null: Allocate new vectors entryoids = new SnmpOid[Delta]; entrylists = new Vector[Delta]; isentrynew = new boolean[Delta]; rowstatus = new SnmpVarBind[Delta]; entrysize = Delta; pos = 0; } else if (pos >= entrysize || entrycount == entrysize) { // Vectors must be enlarged // Save old vectors SnmpOid[] olde = entryoids; Vector[] oldl = entrylists; boolean[] oldn = isentrynew; SnmpVarBind[] oldr = rowstatus; // Allocate larger vectors entrysize += Delta; entryoids = new SnmpOid[entrysize]; entrylists = new Vector[entrysize]; isentrynew = new boolean[entrysize]; rowstatus = new SnmpVarBind[entrysize]; // Check pos validity if (pos > entrycount) pos = entrycount; if (pos < 0) pos = 0; final int l1 = pos; final int l2 = entrycount - pos; // Copy original vectors up to `pos' if (l1 > 0) { java.lang.System.arraycopy(olde,0,entryoids, 0,l1); java.lang.System.arraycopy(oldl,0,entrylists, 0,l1); java.lang.System.arraycopy(oldn,0,isentrynew, 0,l1); java.lang.System.arraycopy(oldr,0,rowstatus, 0,l1); } // Copy original vectors from `pos' to end, leaving // an empty room at `pos' in the new vectors. if (l2 > 0) { final int l3 = l1+1; java.lang.System.arraycopy(olde,l1,entryoids, l3,l2); java.lang.System.arraycopy(oldl,l1,entrylists, l3,l2); java.lang.System.arraycopy(oldn,l1,isentrynew, l3,l2); java.lang.System.arraycopy(oldr,l1,rowstatus, l3,l2); } } else if (pos < entrycount) { // Vectors are large enough to accomodate one additional // entry. // // Shift vectors, making an empty room at `pos' final int l1 = pos+1; final int l2 = entrycount - pos; java.lang.System.arraycopy(entryoids,pos,entryoids, l1,l2); java.lang.System.arraycopy(entrylists,pos,entrylists, l1,l2); java.lang.System.arraycopy(isentrynew,pos,isentrynew, l1,l2); java.lang.System.arraycopy(rowstatus,pos,rowstatus, l1,l2); } // Fill the gap at `pos' entryoids[pos] = oid; entrylists[pos] = v; isentrynew[pos] = isnew; rowstatus[pos] = statusvb; entrycount++; } public void addVarbind(SnmpVarBind varbind, SnmpOid entryoid, boolean isnew, SnmpVarBind statusvb) throws SnmpStatusException { Vector v = null; SnmpVarBind rs = statusvb; if (entryoids == null) {// entryoids = new ArrayList();// entrylists = new ArrayList();// isentrynew = new ArrayList(); v = new Vector();// entryoids.add(entryoid);// entrylists.add(v);// isentrynew.add(new Boolean(isnew)); add(0,entryoid,v,isnew,rs); } else { // int pos = findOid(entryoids,entryoid); // int pos = findOid(entryoids,entrycount,entryoid); final int pos = getInsertionPoint(entryoids,entrycount,entryoid); if (pos > -1 && pos < entrycount && entryoid.compareTo(entryoids[pos]) == 0) { v = entrylists[pos]; rs = rowstatus[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();// entryoids.add(pos,entryoid);// entrylists.add(pos,v);// isentrynew.add(pos,new Boolean(isnew)); add(pos,entryoid,v,isnew,rs); }// } else v = (Vector) entrylists.get(pos); // } else v = entrylists[pos]; if (statusvb != null) { if ((rs != null) && (rs != statusvb) && ((type == SnmpDefinitions.pduWalkRequest) || (type == SnmpDefinitions.pduSetRequestPdu))) { throw new SnmpStatusException( SnmpStatusException.snmpRspInconsistentValue); } rowstatus[pos] = statusvb; } } // We do not include the status variable in the varbind, // because we're going to set it separately... // if (statusvb != varbind) v.addElement(varbind); } public int getSubReqCount() { int count = 0; if (sublist != null) count++;// if (entryoids != null) count += entryoids.size(); if (entryoids != null) count += entrycount; return count; } public Vector getSubList() { return sublist; } public int getEntryPos(SnmpOid entryoid) { // return findOid(entryoids,entryoid); return findOid(entryoids,entrycount,entryoid); } public SnmpOid getEntryOid(int pos) { if (entryoids == null) return null; // if (pos == -1 || pos >= entryoids.size() ) return null; if (pos == -1 || pos >= entrycount ) return null; // return (SnmpOid) entryoids.get(pos); return (SnmpOid) entryoids[pos]; } public boolean isNewEntry(int pos) { if (entryoids == null) return false; // if (pos == -1 || pos >= entryoids.size() ) return false; if (pos == -1 || pos >= entrycount ) return false; // return ((Boolean)isentrynew.get(pos)).booleanValue(); return isentrynew[pos]; } public SnmpVarBind getRowStatusVarBind(int pos) { if (entryoids == null) return null; // if (pos == -1 || pos >= entryoids.size() ) return false; if (pos == -1 || pos >= entrycount ) return null; // return ((Boolean)isentrynew.get(pos)).booleanValue(); return rowstatus[pos]; } public Vector getEntrySubList(int pos) { if (entrylists == null) return null; // if (pos == -1 || pos >= entrylists.size() ) return null; if (pos == -1 || pos >= entrycount ) return null; // return (Vector) entrylists.get(pos); return entrylists[pos]; } public Iterator getEntryOids() { if (entryoids == null) return null; // return entryoids.iterator(); return Arrays.asList(entryoids).iterator(); } public int getEntryCount() { if (entryoids == null) return 0; // return entryoids.size(); return entrycount; } } //------------------------------------------------------------------- //------------------------------------------------------------------- // Public interface //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- // Returns the contextual object containing user-data allocated // through the SnmpUserDataFactory for this request. //------------------------------------------------------------------- public Object getUserData() { return request.getUserData(); } //------------------------------------------------------------------- // Tells whether creation of new entries is allowed with respect // to the operation involved (GET=>false/SET=>true) //------------------------------------------------------------------- public boolean isCreationAllowed() { return creationflag;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -