From 29226513404b0c460479b4dba6a72e02682707e4 Mon Sep 17 00:00:00 2001 From: oana Date: Thu, 23 Jan 2014 11:43:40 +0000 Subject: [PATCH] Replaced include of yatengine.h with yateclass.h. Moved class which was using an Engine class to the SNMP module. git-svn-id: http://voip.null.ro/svn/yate@5740 acf43c95-373e-0410-b603-e72c3f656dc1 --- libs/yasn/asn.cpp | 155 +--------------------------- libs/yasn/yateasn.h | 71 +------------ modules/server/ysnmpagent.cpp | 184 ++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+), 224 deletions(-) diff --git a/libs/yasn/asn.cpp b/libs/yasn/asn.cpp index 3c542c15..50b803c6 100644 --- a/libs/yasn/asn.cpp +++ b/libs/yasn/asn.cpp @@ -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(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(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(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(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(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(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(); -} + diff --git a/libs/yasn/yateasn.h b/libs/yasn/yateasn.h index f4648c23..6841b73e 100644 --- a/libs/yasn/yateasn.h +++ b/libs/yasn/yateasn.h @@ -22,7 +22,7 @@ #ifndef __YATEASN_H #define __YATEASN_H -#include +#include #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 */ diff --git a/modules/server/ysnmpagent.cpp b/modules/server/ysnmpagent.cpp index 2cdfaa41..856a8d00 100644 --- a/modules/server/ysnmpagent.cpp +++ b/modules/server/ysnmpagent.cpp @@ -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(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(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(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(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(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(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