⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diameter_api.h

📁 Diameter协议栈
💻 H
📖 第 1 页 / 共 2 页
字号:
    public AAASession,    public AAA_ServerAuthSession{    public:        AAAServerSession(AAAApplicationCore &appCore,                         diameter_unsigned32_t id) :	    AAASession(appCore, id),	    AAA_ServerAuthSession(appCore.GetTask(), id) {	    m_IO = this;	}        virtual ~AAAServerSession() {            End();	}        AAAReturnCode Abort() {	    return End();	}    private:        virtual AAAReturnCode RequestMsg(AAAMessage &msg) {	    return CheckUpdateEvent(msg);        }        virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {	    return CallMsgHandler(msg);	}        virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {	    return CallMsgHandler(msg);	}        virtual AAAReturnCode Disconnect() {            return this->HandleDisconnect();        }        virtual AAAReturnCode SessionTimeout() {	    this->HandleTimeout();	    return this->HandleSessionTimeout();        }        virtual AAAReturnCode AuthorizationTimeout() {	    this->HandleAuthGracePeriodTimeout();	    return this->HandleAuthLifetimeTimeout();        }        virtual AAAReturnCode AbortSession() {	    return this->HandleAbort();        }        AAAReturnCode CheckUpdateEvent(AAAMessage &msg) {	    CallMsgHandler(msg);	    switch (m_LastEvent) {	    case EVENT_AUTH_SUCCESS:  return AAA_ERR_SUCCESS;            case EVENT_AUTH_CONTINUE: return AAA_ERR_INCOMPLETE;            default: return AAA_ERR_FAILURE;	    }	}};class DIAMETERBASEPROTOCOL_EXPORT AAAMessageControl {    public:        AAAMessageControl(AAASession *s) :             m_Session(*s) {        }        virtual ~AAAMessageControl() {	}        AAAReturnCode SetResultCode(AAAMessage &response,                                     AAAMessage &request,                                     AAAResultCode resultCode) {           AAA_MsgResultCode rcode(response);           rcode.ResultCode(resultCode);           return (AAA_ERR_SUCCESS);	}        AAAReturnCode Send(AAAMessage &msg) {	   std::auto_ptr<AAAMessage> newMsg(new AAAMessage);           newMsg->hdr = msg.hdr;                     while (! msg.acl.empty()) {	       AAAAvpContainer *c = msg.acl.front();               msg.acl.pop_front();               newMsg->acl.add(c);	   }           AAA_IdentityAvpContainerWidget oHostAvp(newMsg->acl);           AAA_IdentityAvpContainerWidget oRealmAvp(newMsg->acl);           // resolve origin host           diameter_identity_t *oHost = oHostAvp.GetAvp                 (AAA_AVPNAME_ORIGINHOST);           if (oHost == NULL) {               oHostAvp.AddAvp(AAA_AVPNAME_ORIGINHOST) = 		   AAA_CFG_TRANSPORT()->identity;           }           else if (oHost->length() == 0) {	       *oHost = AAA_CFG_TRANSPORT()->identity;	   }           // resolve origin realm           diameter_identity_t *oRealm = oRealmAvp.GetAvp                   (AAA_AVPNAME_ORIGINREALM);           if (oRealm == NULL) {               oRealmAvp.AddAvp(AAA_AVPNAME_ORIGINREALM) = 		   AAA_CFG_TRANSPORT()->realm;           }           else if (oRealm->length() == 0) {	       *oRealm = AAA_CFG_TRANSPORT()->realm;	   }	   return m_Session.IO()->Send(newMsg);	}    protected:        AAASession &m_Session;};class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingSession :     public AAASession{    public:        AAAAccountingSession(AAAApplicationCore &appCore,                             diameter_unsigned32_t id) :	    AAASession(appCore, id) {	}        virtual ~AAAAccountingSession() {	}        AAAReturnCode Send(AAAMessage &reqMsg) {	    AAAMessageControl msgCntrl(this);            return msgCntrl.Send(reqMsg);	}};class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingClientSession :     public AAAAccountingSession{    private:        class LocalCollector : public AAA_ClientAcctRecCollector {            public:	        LocalCollector() :                    m_Session(0) {	        }                virtual void GenerateRecord(AAAAvpContainerList &avpList,                                            int recordType,                                            int recordNum) {		    if (m_Session) {		       m_Session->HandleInterimRecordEvent                          ((AAAAccountingClientSession::RECTYPE)recordType,			   m_Session->m_LastPayload);		    }		}                virtual bool IsLastRecordInStorage() {		    return (false);		}                virtual bool IsStorageSpaceAvailable() {		    return (true);		}                virtual AAAReturnCode StoreLastRecord(int recordType) {		    return (AAA_ERR_SUCCESS);		}                virtual AAAReturnCode DeleteLastRecord(int recordType) {		    return (AAA_ERR_SUCCESS);		}                AAAAccountingClientSession *m_Session;                friend class AAAAccountingClientSession;        };    public:        typedef enum {            RECTYPE_EVENT = 1,            RECTYPE_START = 2,            RECTYPE_INTERIM = 3,            RECTYPE_STOP = 4        } RECTYPE;    public:        AAAAccountingClientSession(AAAApplicationCore &appCore,                                   diameter_unsigned32_t id) :	   AAAAccountingSession(appCore, id),	   m_ParentSession(appCore.GetTask(), id),           m_LastPayload(NULL) {           m_SubSession = std::auto_ptr<AAA_ClientAcctSubSession<LocalCollector> >                (new AAA_ClientAcctSubSession<LocalCollector>(m_ParentSession));           m_SubSession->RecCollector().m_Session = this;           m_IO = m_SubSession.get();           m_SubSession->Attributes().BackwardCompatibility() = true;	}        virtual ~AAAAccountingClientSession() {	}        AAAReturnCode SetInterimRecordInterval(RECTYPE type,                                                int interval = 0,                                               AAASessionPayload payload = NULL) {	   AAA_CFG_ACCT_SESSION()->recIntervalTm = interval;           m_LastPayload = payload;           switch (type) {	      case RECTYPE_EVENT: m_SubSession->Begin(true); break;              case RECTYPE_START: m_SubSession->Begin(false); break;              case RECTYPE_INTERIM: break;              case RECTYPE_STOP: m_SubSession->End(); break;	   }           return (AAA_ERR_SUCCESS);	}        virtual AAAReturnCode HandleInterimRecordEvent(RECTYPE type,                                                        AAASessionPayload payload) {	   return (AAA_ERR_SUCCESS);	}     private:        AAA_ClientAcctSession m_ParentSession;        std::auto_ptr<AAA_ClientAcctSubSession<LocalCollector> >               m_SubSession;        AAASessionPayload m_LastPayload;};class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingRecTransformer{    public:        AAAAccountingRecTransformer() {        }        virtual ~AAAAccountingRecTransformer() {	}        virtual AAAReturnCode Convert(AAAMessage *msg) = 0;        virtual AAAReturnCode OutputRecord(AAAMessage *originalMsg) = 0;};class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingXMLRecTransformer :     public AAAAccountingRecTransformer{    public:        AAAAccountingXMLRecTransformer() {        }        virtual ~AAAAccountingXMLRecTransformer() {	}        virtual AAAReturnCode Convert(AAAMessage *msg);        virtual AAAReturnCode OutputRecord(AAAMessage *originalMsg);   protected:        AAASessionPayload record;        ACE_UINT32 record_size;};class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingServerSession :     public AAAAccountingSession{    private:        class LocalStorage : public AAA_ServerAcctRecStorage        {            public:	       LocalStorage() :                  m_Session(0) {	       }	       virtual bool IsSpaceAvailableOnDevice() {		  return (true);	       }               virtual void StoreRecord(AAAAvpContainerList &avpList,                                        int recordType,                                        int recordNum) {		  if (m_Session) {		      AAAMessage msg;                      ACE_OS::memset(&msg.hdr, 0, sizeof(msg.hdr));                      msg.hdr.ver = AAA_PROTOCOL_VERSION;                      msg.hdr.length = 0;                      msg.hdr.flags.r = AAA_FLG_SET;                      msg.hdr.flags.p = AAA_FLG_CLR;                      msg.hdr.flags.e = AAA_FLG_CLR;                      msg.hdr.code = AAA_MSGCODE_ACCOUNTING;                      msg.hdr.appId = m_Session->GetApplicationId();                      while (! avpList.empty()) {	                  AAAAvpContainer *c = avpList.front();                          avpList.pop_front();                          msg.acl.add(c);	              }                      m_Session->GetTransformer()->Convert(&msg);                      m_Session->GetTransformer()->OutputRecord(&msg);		  }	       }                          virtual void UpdateAcctResponse(AAAMessage &aca) {	       }               AAAAccountingServerSession *m_Session;        };    public:        AAAAccountingServerSession(AAAApplicationCore &appCore,                                   diameter_unsigned32_t id) :	    AAAAccountingSession(appCore, id) {            m_Session = std::auto_ptr<AAA_ServerAcctSession<LocalStorage> >                (new AAA_ServerAcctSession<LocalStorage>(appCore.GetTask(), id));            m_Session->RecStorage().m_Session = this;            m_Session->Attributes().BackwardCompatibility() = true;            m_IO = m_Session.get();	}        virtual ~AAAAccountingServerSession() {	}        void SetTransformer(AAAAccountingRecTransformer *trns) {             m_Transformer = trns;         }	AAAAccountingRecTransformer *GetTransformer() {             return m_Transformer;         }    protected:        AAAAccountingRecTransformer *m_Transformer;        std::auto_ptr<AAA_ServerAcctSession<LocalStorage> >	    m_Session;};class DIAMETERBASEPROTOCOL_EXPORT AAAProxyServices{        private:        class LocalHandler : public AAA_ProxyHandler        {           public:               LocalHandler(AAAEventHandler *h,                            diameter_unsigned32_t appId) :                  		  AAA_ProxyHandler(appId),		  m_ApplicationId(appId),                  m_Handler(h) {               }               virtual ~LocalHandler() {               }               virtual AAAReturnCode RequestMsg(AAAMessage &msg) {		  return m_Handler->HandleMessage(msg);               }               virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {		  return m_Handler->HandleMessage(msg);               }               virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {		  return m_Handler->HandleMessage(msg);               }               diameter_unsigned32_t &ApplicationId() {                  return m_ApplicationId;               }           protected:               diameter_unsigned32_t m_ApplicationId;               AAAEventHandler *m_Handler;        };        typedef std::map<diameter_unsigned32_t,                         LocalHandler*>                         AAAHandlerMap;        typedef std::pair<diameter_unsigned32_t,                          LocalHandler*>                          AAAHandlerMapPair;    public:        AAAProxyServices(AAAApplicationCore &appCore) :            m_Core(appCore) {        }        virtual ~AAAProxyServices() { 	    while (! m_HandlerMap.empty()) {	        AAAHandlerMap::iterator i = m_HandlerMap.begin();                delete i->second;                m_HandlerMap.erase(i);	    }        }        AAAReturnCode RegisterMessageHandler(diameter_unsigned32_t appId,                                             AAAEventHandler *handler) {	    AAAHandlerMap::iterator i = m_HandlerMap.find(appId);	    if (m_HandlerMap.end() != i) {	        return (AAA_ERR_FAILURE);	    }            LocalHandler *h = new LocalHandler(handler, appId);            if (h) {                m_HandlerMap.insert(AAAHandlerMapPair(appId, h));                return (AAA_ERR_SUCCESS);            	    }            return (AAA_ERR_FAILURE);	}        AAAReturnCode RemoveMessageHandler(diameter_unsigned32_t appId) {	    AAAHandlerMap::iterator i = m_HandlerMap.find(appId);	    if (m_HandlerMap.end() != i) {	        delete i->second;                m_HandlerMap.erase(i);	    }            return (AAA_ERR_SUCCESS);            	}    protected:        AAAApplicationCore &m_Core;        AAAHandlerMap m_HandlerMap;};#endif   // __DIAMETER_API_H__ 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -