Replaced include of yatengine.h with yateclass.h.
Moved class which was using an Engine class to the SNMP module. git-svn-id: http://yate.null.ro/svn/yate/trunk@5740 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
fd44402cb4
commit
0960497615
|
@ -1460,159 +1460,6 @@ int AsnMib::compareTo(AsnMib* mib)
|
|||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* AsnMibTree
|
||||
*/
|
||||
AsnMibTree::AsnMibTree(const String& fileName)
|
||||
{
|
||||
DDebug(s_libName.c_str(),DebugAll,"AsnMibTree object created from %s", fileName.c_str());
|
||||
m_treeConf = fileName;
|
||||
buildTree();
|
||||
}
|
||||
|
||||
AsnMibTree::~AsnMibTree()
|
||||
{
|
||||
m_mibs.clear();
|
||||
}
|
||||
|
||||
void AsnMibTree::buildTree()
|
||||
{
|
||||
Configuration cfgTree;
|
||||
cfgTree = m_treeConf;
|
||||
if(!cfgTree.load())
|
||||
Debug(s_libName.c_str(),DebugWarn,"Failed to load MIB tree");
|
||||
else {
|
||||
for (unsigned int i = 0; i < cfgTree.sections(); i++) {
|
||||
NamedList* sect = cfgTree.getSection(i);
|
||||
if (sect) {
|
||||
AsnMib* mib = new AsnMib(*sect);
|
||||
m_mibs.append(mib);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String AsnMibTree::findRevision(const String& name)
|
||||
{
|
||||
AsnMib* mib = find(name);
|
||||
if (!mib)
|
||||
return "";
|
||||
String revision = "";
|
||||
while (revision.null()) {
|
||||
ASNObjId parentID = mib->getParent();
|
||||
AsnMib* parent = find(parentID);
|
||||
if (!parent)
|
||||
return revision;
|
||||
revision = parent->getRevision();
|
||||
mib = parent;
|
||||
}
|
||||
return revision;
|
||||
}
|
||||
|
||||
AsnMib* AsnMibTree::find(const String& name)
|
||||
{
|
||||
DDebug(s_libName.c_str(),DebugAll,"AsnMibTree::find('%s')",name.c_str());
|
||||
const ObjList *n = m_mibs.skipNull();
|
||||
AsnMib* mib = 0;
|
||||
while (n) {
|
||||
mib = static_cast<AsnMib*>(n->get());
|
||||
if (name == mib->getName())
|
||||
break;
|
||||
n = n->skipNext();
|
||||
mib = 0;
|
||||
}
|
||||
return mib;
|
||||
}
|
||||
|
||||
AsnMib* AsnMibTree::find(const ASNObjId& id)
|
||||
{
|
||||
DDebug(s_libName.c_str(),DebugAll,"AsnMibTree::find('%s')",id.toString().c_str());
|
||||
|
||||
String value = id.toString();
|
||||
int pos = 0;
|
||||
int index = 0;
|
||||
AsnMib* searched = 0;
|
||||
unsigned int cycles = 0;
|
||||
while (cycles < 2) {
|
||||
ObjList* n = m_mibs.find(value);
|
||||
searched = n ? static_cast<AsnMib*>(n->get()) : 0;
|
||||
if (searched) {
|
||||
searched->setIndex(index);
|
||||
return searched;
|
||||
}
|
||||
pos = value.rfind('.');
|
||||
if (pos < 0)
|
||||
return 0;
|
||||
index = value.substr(pos + 1).toInteger();
|
||||
value = value.substr(0,pos);
|
||||
cycles++;
|
||||
}
|
||||
return searched;
|
||||
}
|
||||
|
||||
AsnMib* AsnMibTree::findNext(const ASNObjId& id)
|
||||
{
|
||||
DDebug(s_libName.c_str(),DebugAll,"AsnMibTree::findNext('%s')",id.toString().c_str());
|
||||
String searchID = id.toString();
|
||||
// check it the oid is in our known tree
|
||||
AsnMib* root = static_cast<AsnMib*>(m_mibs.get());
|
||||
if (root && !(id.toString().startsWith(root->toString()))) {
|
||||
NamedList p(id.toString());
|
||||
AsnMib oid(p);
|
||||
int comp = oid.compareTo(root);
|
||||
if (comp < 0)
|
||||
searchID = root->toString();
|
||||
else if (comp > 0)
|
||||
return 0;
|
||||
}
|
||||
AsnMib* searched = static_cast<AsnMib*>(m_mibs[searchID.toString()]);
|
||||
if (searched) {
|
||||
if (searched->getAccessValue() > AsnMib::accessibleForNotify) {
|
||||
DDebug(s_libName.c_str(),DebugInfo,"AsnMibTree::findNext('%s') - found an exact match to be '%s'",
|
||||
id.toString().c_str(), searched->toString().c_str());
|
||||
return searched;
|
||||
}
|
||||
}
|
||||
String value = searchID.toString();
|
||||
int pos = 0;
|
||||
int index = 0;
|
||||
while (true) {
|
||||
ObjList* n = m_mibs.find(value);
|
||||
searched = n ? static_cast<AsnMib*>(n->get()) : 0;
|
||||
if (searched) {
|
||||
if (id.toString() == searched->getOID() || id.toString() == searched->toString()) {
|
||||
ObjList* aux = n->skipNext();
|
||||
if (!aux)
|
||||
return 0;
|
||||
while (aux) {
|
||||
AsnMib* mib = static_cast<AsnMib*>(aux->get());
|
||||
if (mib && mib->getAccessValue() > AsnMib::accessibleForNotify)
|
||||
return mib;
|
||||
aux = aux->skipNext();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
searched->setIndex(index + 1);
|
||||
return searched;
|
||||
}
|
||||
}
|
||||
pos = value.rfind('.');
|
||||
if (pos < 0)
|
||||
return 0;
|
||||
index = value.substr(pos + 1).toInteger();
|
||||
value = value.substr(0,pos);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AsnMibTree::getAccess(const ASNObjId& id)
|
||||
{
|
||||
DDebug(s_libName.c_str(),DebugAll,"AsnMibTree::getAccess('%s')",id.toString().c_str());
|
||||
AsnMib* mib = find(id);
|
||||
if (!mib)
|
||||
return 0;
|
||||
return mib->getAccessValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#ifndef __YATEASN_H
|
||||
#define __YATEASN_H
|
||||
|
||||
#include <yatengine.h>
|
||||
#include <yateclass.h>
|
||||
|
||||
#ifdef _WINDOWS
|
||||
|
||||
|
@ -49,7 +49,6 @@ namespace TelEngine {
|
|||
|
||||
class AsnObject;
|
||||
class AsnValue;
|
||||
class AsnMibTree;
|
||||
class ASNObjId;
|
||||
class ASNLib;
|
||||
class ASNError;
|
||||
|
@ -386,74 +385,6 @@ private:
|
|||
static TokenDict s_access[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Tree of OIDs.
|
||||
*/
|
||||
class YASN_API AsnMibTree : public GenObject {
|
||||
YCLASS(AsnMibTree, GenObject)
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
inline AsnMibTree()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param fileName File from which the tree is to be built
|
||||
*/
|
||||
AsnMibTree(const String& fileName);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~AsnMibTree();
|
||||
|
||||
/**
|
||||
* Find a MIB object given the object id
|
||||
* @param id The object id
|
||||
* @return A pointer to the MIB with the searched object id, 0 if not found
|
||||
*/
|
||||
AsnMib* find(const ASNObjId& id);
|
||||
|
||||
/**
|
||||
* Find a MIB given the MIB name
|
||||
* @param name The name of the MIB object
|
||||
* @return A pointer to the MIB with the searched object id, 0 if not found
|
||||
*/
|
||||
AsnMib* find(const String& name);
|
||||
|
||||
/**
|
||||
* Find the next MIB object in the tree
|
||||
* @param id Object id of the current MIB object
|
||||
* @return A pointer to the next MIB object in the tree, 0 if there is no next
|
||||
*/
|
||||
AsnMib* findNext(const ASNObjId& id);
|
||||
|
||||
/**
|
||||
* Get access level for the given object id
|
||||
* @param oid Object id for which the access level is required
|
||||
* @return Enum value describing the access level required for this object
|
||||
*/
|
||||
int getAccess(const ASNObjId& oid);
|
||||
|
||||
/**
|
||||
* Build the tree of MIB objects
|
||||
*/
|
||||
void buildTree();
|
||||
|
||||
/**
|
||||
* Find the module revision of which this OID is part of
|
||||
* @param name Name of the OID
|
||||
* @return String value of the module revision
|
||||
*/
|
||||
String findRevision(const String& name);
|
||||
|
||||
private:
|
||||
String m_treeConf;
|
||||
ObjList m_mibs;
|
||||
};
|
||||
|
||||
/**
|
||||
* Class for holding only an OID
|
||||
*/
|
||||
|
|
|
@ -63,6 +63,7 @@ class SnmpUser;
|
|||
|
||||
class SnmpUdpListener;
|
||||
class TrapHandler;
|
||||
class AsnMibTree;
|
||||
|
||||
/**
|
||||
* TransportType
|
||||
|
@ -518,6 +519,35 @@ private:
|
|||
Cipher* m_cipher;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tree of OIDs.
|
||||
*/
|
||||
class AsnMibTree : public GenObject {
|
||||
YCLASS(AsnMibTree, GenObject)
|
||||
public:
|
||||
inline AsnMibTree()
|
||||
{}
|
||||
// Constructor with file name from which the tree is to be built
|
||||
AsnMibTree(const String& fileName);
|
||||
virtual ~AsnMibTree();
|
||||
// Find a MIB object given the object id
|
||||
AsnMib* find(const ASNObjId& id);
|
||||
// Find a MIB given the MIB name
|
||||
AsnMib* find(const String& name);
|
||||
// Find the next MIB object in the tree
|
||||
AsnMib* findNext(const ASNObjId& id);
|
||||
// Get access level for the given object id
|
||||
int getAccess(const ASNObjId& oid);
|
||||
// Build the tree of MIB objects
|
||||
void buildTree();
|
||||
//Find the module revision of which this OID is part of
|
||||
String findRevision(const String& name);
|
||||
|
||||
private:
|
||||
String m_treeConf;
|
||||
ObjList m_mibs;
|
||||
};
|
||||
|
||||
const TokenDict TransportType::s_typeText[] = {
|
||||
{"UDP", UDP},
|
||||
{"TCP", TCP},
|
||||
|
@ -633,6 +663,160 @@ UNLOAD_PLUGIN(unloadNow)
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* AsnMibTree
|
||||
*/
|
||||
AsnMibTree::AsnMibTree(const String& fileName)
|
||||
{
|
||||
DDebug(&__plugin,DebugAll,"AsnMibTree object created from %s", fileName.c_str());
|
||||
m_treeConf = fileName;
|
||||
buildTree();
|
||||
}
|
||||
|
||||
AsnMibTree::~AsnMibTree()
|
||||
{
|
||||
m_mibs.clear();
|
||||
}
|
||||
|
||||
void AsnMibTree::buildTree()
|
||||
{
|
||||
Configuration cfgTree;
|
||||
cfgTree = m_treeConf;
|
||||
if(!cfgTree.load())
|
||||
Debug(&__plugin,DebugWarn,"Failed to load MIB tree");
|
||||
else {
|
||||
for (unsigned int i = 0; i < cfgTree.sections(); i++) {
|
||||
NamedList* sect = cfgTree.getSection(i);
|
||||
if (sect) {
|
||||
AsnMib* mib = new AsnMib(*sect);
|
||||
m_mibs.append(mib);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String AsnMibTree::findRevision(const String& name)
|
||||
{
|
||||
AsnMib* mib = find(name);
|
||||
if (!mib)
|
||||
return "";
|
||||
String revision = "";
|
||||
while (revision.null()) {
|
||||
ASNObjId parentID = mib->getParent();
|
||||
AsnMib* parent = find(parentID);
|
||||
if (!parent)
|
||||
return revision;
|
||||
revision = parent->getRevision();
|
||||
mib = parent;
|
||||
}
|
||||
return revision;
|
||||
}
|
||||
|
||||
AsnMib* AsnMibTree::find(const String& name)
|
||||
{
|
||||
DDebug(&__plugin,DebugAll,"AsnMibTree::find('%s')",name.c_str());
|
||||
const ObjList *n = m_mibs.skipNull();
|
||||
AsnMib* mib = 0;
|
||||
while (n) {
|
||||
mib = static_cast<AsnMib*>(n->get());
|
||||
if (name == mib->getName())
|
||||
break;
|
||||
n = n->skipNext();
|
||||
mib = 0;
|
||||
}
|
||||
return mib;
|
||||
}
|
||||
|
||||
AsnMib* AsnMibTree::find(const ASNObjId& id)
|
||||
{
|
||||
DDebug(&__plugin,DebugAll,"AsnMibTree::find('%s')",id.toString().c_str());
|
||||
|
||||
String value = id.toString();
|
||||
int pos = 0;
|
||||
int index = 0;
|
||||
AsnMib* searched = 0;
|
||||
unsigned int cycles = 0;
|
||||
while (cycles < 2) {
|
||||
ObjList* n = m_mibs.find(value);
|
||||
searched = n ? static_cast<AsnMib*>(n->get()) : 0;
|
||||
if (searched) {
|
||||
searched->setIndex(index);
|
||||
return searched;
|
||||
}
|
||||
pos = value.rfind('.');
|
||||
if (pos < 0)
|
||||
return 0;
|
||||
index = value.substr(pos + 1).toInteger();
|
||||
value = value.substr(0,pos);
|
||||
cycles++;
|
||||
}
|
||||
return searched;
|
||||
}
|
||||
|
||||
AsnMib* AsnMibTree::findNext(const ASNObjId& id)
|
||||
{
|
||||
DDebug(&__plugin,DebugAll,"AsnMibTree::findNext('%s')",id.toString().c_str());
|
||||
String searchID = id.toString();
|
||||
// check it the oid is in our known tree
|
||||
AsnMib* root = static_cast<AsnMib*>(m_mibs.get());
|
||||
if (root && !(id.toString().startsWith(root->toString()))) {
|
||||
NamedList p(id.toString());
|
||||
AsnMib oid(p);
|
||||
int comp = oid.compareTo(root);
|
||||
if (comp < 0)
|
||||
searchID = root->toString();
|
||||
else if (comp > 0)
|
||||
return 0;
|
||||
}
|
||||
AsnMib* searched = static_cast<AsnMib*>(m_mibs[searchID.toString()]);
|
||||
if (searched) {
|
||||
if (searched->getAccessValue() > AsnMib::accessibleForNotify) {
|
||||
DDebug(&__plugin,DebugInfo,"AsnMibTree::findNext('%s') - found an exact match to be '%s'",
|
||||
id.toString().c_str(), searched->toString().c_str());
|
||||
return searched;
|
||||
}
|
||||
}
|
||||
String value = searchID.toString();
|
||||
int pos = 0;
|
||||
int index = 0;
|
||||
while (true) {
|
||||
ObjList* n = m_mibs.find(value);
|
||||
searched = n ? static_cast<AsnMib*>(n->get()) : 0;
|
||||
if (searched) {
|
||||
if (id.toString() == searched->getOID() || id.toString() == searched->toString()) {
|
||||
ObjList* aux = n->skipNext();
|
||||
if (!aux)
|
||||
return 0;
|
||||
while (aux) {
|
||||
AsnMib* mib = static_cast<AsnMib*>(aux->get());
|
||||
if (mib && mib->getAccessValue() > AsnMib::accessibleForNotify)
|
||||
return mib;
|
||||
aux = aux->skipNext();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
searched->setIndex(index + 1);
|
||||
return searched;
|
||||
}
|
||||
}
|
||||
pos = value.rfind('.');
|
||||
if (pos < 0)
|
||||
return 0;
|
||||
index = value.substr(pos + 1).toInteger();
|
||||
value = value.substr(0,pos);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AsnMibTree::getAccess(const ASNObjId& id)
|
||||
{
|
||||
DDebug(&__plugin,DebugAll,"AsnMibTree::getAccess('%s')",id.toString().c_str());
|
||||
AsnMib* mib = find(id);
|
||||
if (!mib)
|
||||
return 0;
|
||||
return mib->getAccessValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* TrapHandler - message handler for incoming notifications
|
||||
|
|
Loading…
Reference in New Issue