[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Mibble-users] Reverse usage of mibble
From: |
Per Cederberg |
Subject: |
Re: [Mibble-users] Reverse usage of mibble |
Date: |
Sun, 04 Apr 2004 12:12:53 +0200 |
On Fri, 2004-04-02 at 05:52, delphiVcl wrote:
> hiļ¼per
> My email has been changed .
> I have received no email since 2004/03/18.
> on http://mail.gnu.org/archive/html/mibble-users/2004-03/msg00016.html I find
> your answer to my email .
The last post to the list (before yours that is) was my answer.
I guess that explains why you didn't get any mail from the list.
> For example , I try to translate "1.3.6.1.2.1.1.1.0" to "sysDescr.0".
I think I understand the issue. Thing is, if you haven't defined
a symbol corresponding to sysDescr.0 in the MIB (like
sysDescrEntry or similar), the method I sent to the list will
return null. It only returns symbols on *exact* matches. It will
NOT return parent (or ancestor) symbols.
In your case, I think you are really looking for this (minus any
compilation errors):
public MibValueSymbol findSymbolByOid(String oid,
boolean exact) {
MibValueSymbol sym;
int pos;
int value;
sym = this.getSymbolByValue(oid);
if (sym == null) {
pos = oid.lastIndexOf(".");
if (pos > 0) {
sym = findSymbolByOid(oid.substring(0, pos), true);
if (sym != null) {
value = Integer.parseInt(oid.substring(pos + 1));
sym = findSymbolChild(sym, value, exact);
} else if (!exact) {
sym = findSymbolByOid(oid.substring(0, pos), false);
}
}
}
return sym;
}
public MibValueSymbol findSymbolChild(MibValueSymbol sym,
int value,
boolean exact) {
ObjectIdentifierValue oid;
if (!(sym.getValue() instanceof ObjectIdentifierValue)) {
return null;
}
oid = (ObjectIdentifierValue) sym.getValue();
for (int i = 0; i < oid.getChildCount(); i++) {
if (oid.getChild(i).getValue() == value) {
return oid.getChild(i).getSymbol();
}
}
if (oid.getChildCount() == 1) {
return oid.getChild(0).getSymbol();
} else if (!exact) {
return sym;
} else {
return null;
}
}
You'd call the above with findSymbolByOid(oid, false), whereas
a lot of other people would probably like exact matches (using
true). If you're using non-exact matches, you will get the last
matching ancestor to the oid, which might be "enterprise" or
something like that if you're unlucky...
Note that I had to change the findSymbolByOid() method in order
to correctly handle cases like "1.2.3.4" only finding a match on
"1.2" and thereafter skipping any further attempts at matching.
The code is not the most efficient and I'll probably improve it
a bit before including it in the next Mibble release.
Hope this version suits you better!
Cheers,
/Per