📄 diameter_api.h
字号:
/* BEGIN_COPYRIGHT *//* *//* Open Diameter: Open-source software for the Diameter and *//* Diameter related protocols *//* *//* Copyright (C) 2002-2004 Open Diameter Project *//* *//* This library is free software; you can redistribute it and/or modify *//* it under the terms of the GNU Lesser General Public License as *//* published by the Free Software Foundation; either version 2.1 of the *//* License, or (at your option) any later version. *//* *//* This library is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *//* Lesser General Public License for more details. *//* *//* You should have received a copy of the GNU Lesser General Public *//* License along with this library; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *//* USA. *//* *//* In addition, when you copy and redistribute some or the entire part of *//* the source code of this software with or without modification, you *//* MUST include this copyright notice in each copy. *//* *//* If you make any changes that are appeared to be useful, please send *//* sources that include the changed part to *//* diameter-developers@lists.sourceforge.net so that we can reflect your *//* changes to one unified version of this software. *//* *//* END_COPYRIGHT */#ifndef __DIAMETER_API_H__#define __DIAMETER_API_H__/*! * Windows specific export declarations */#if defined (WIN32)# if defined (DIAMETERBASEPROTOCOL_EXPORTS)# define DIAMETERBASEPROTOCOL_EXPORT ACE_Proper_Export_Flag# define DIAMETERBASEPROTOCOL_EXPORT_ONLY ACE_Proper_Export_Flag# define DIAMETERBASEPROTOCOL_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)# define DIAMETERBASEPROTOCOL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)# else# define DIAMETERBASEPROTOCOL_EXPORT ACE_Proper_Import_Flag# define DIAMETERBASEPROTOCOL_EXPORT_ONLY# define DIAMETERBASEPROTOCOL_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)# define DIAMETERBASEPROTOCOL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)# endif /* ! DIAMETERBASEPROTOCOL_EXPORTS */#else# define DIAMETERBASEPROTOCOL_EXPORT# define DIAMETERBASEPROTOCOL_EXPORT_ONLY# define DIAMETERBASEPROTOCOL_SINGLETON_DECLARATION(T)# define DIAMETERBASEPROTOCOL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)#endif /* WIN32 */#include "aaa_application.h"#include "aaa_session_client.h"#include "aaa_session_server.h"#include "aaa_session_server_factory.h"//////////////////////////////////////////////////////////////////////////////////////////////// !!!! WARNING !!!! ///////////////////////////// THE FOLLOWING ARE OLD COMPATIBILITY API's ///////////////////////////// NEW APPLICATIONS SHOULD NOT USE THESE API's ///////////////////////////////////////////////////////////////////////////////////////////////////typedef AAA_ServerSessionFactory AAAServerSessionFactory;typedef std::auto_ptr<AAA_Application> AAAApplicationHandle;typedef void* AAASessionPayload;class DIAMETERBASEPROTOCOL_EXPORT AAAApplicationCore { public: AAAApplicationCore() { } AAAApplicationCore(char *configFileName, AAA_Task &task) { Open(configFileName, task); } virtual ~AAAApplicationCore() { Close(); } AAAReturnCode Open(char *configFileName, AAA_Task &task) { if (! m_Handle.get()) { m_Handle = std::auto_ptr<AAA_Application> (new AAA_Application(task)); return m_Handle->Open(configFileName); } return (AAA_ERR_SUCCESS); } AAAReturnCode Close() { if (m_Handle.get()) { m_Handle->Close(); m_Handle.reset(); } return (AAA_ERR_SUCCESS); } AAAReturnCode RegisterServerSessionFactory (AAAServerSessionFactory *factory) { if (m_Handle.get()) { return m_Handle->RegisterServerSessionFactory (*factory); } return (AAA_ERR_SUCCESS); } AAAReturnCode RemoveServerSessionFactory (AAAServerSessionFactory *factory) { if (m_Handle.get()) { return m_Handle->RemoveServerSessionFactory (factory->GetApplicationId()); } return (AAA_ERR_SUCCESS); } AAAApplicationHandle &GetAppHandle() { return m_Handle; } diameter_unsigned32_t GetNumActivePeerConnections() { if (m_Handle.get()) { return m_Handle->NumActivePeers(); } return (0); } AAA_Task& GetTask() { // warning - this will throw if m_Handle is invalid return m_Handle->Task(); } private: std::auto_ptr<AAA_Application> m_Handle;};template<class SESSION_SERVER>class AAAServerSessionClassFactory : public AAAServerSessionFactory{ public: AAAServerSessionClassFactory(AAAApplicationCore &c, diameter_unsigned32_t appId) : AAAServerSessionFactory(c.GetTask(), appId), m_Core(c) { } AAA_SessionIO *CreateInstance() { SESSION_SERVER *s = new SESSION_SERVER (m_Core, GetApplicationId()); return s->IO(); } private: AAAApplicationCore &m_Core;};class DIAMETERBASEPROTOCOL_EXPORT AAAPeerManager : public AAA_PeerManager{ public: AAAPeerManager(AAAApplicationCore &core) : AAA_PeerManager(core.GetTask()) { }};class DIAMETERBASEPROTOCOL_EXPORT AAAEventHandler { public: AAAEventHandler(AAAApplicationCore &c) : m_Core(c) { } virtual ~AAAEventHandler() { } virtual AAAReturnCode HandleMessage(AAAMessage &msg) { return (AAA_ERR_SUCCESS); } virtual AAAReturnCode HandleDisconnect() { return (AAA_ERR_SUCCESS); } virtual AAAReturnCode HandleTimeout() { return (AAA_ERR_SUCCESS); } virtual AAAReturnCode HandleSessionTimeout() { return (AAA_ERR_SUCCESS); } virtual AAAReturnCode HandleAuthLifetimeTimeout() { return (AAA_ERR_SUCCESS); } virtual AAAReturnCode HandleAuthGracePeriodTimeout() { return (AAA_ERR_SUCCESS); } virtual AAAReturnCode HandleAbort() { return (AAA_ERR_SUCCESS); } const AAAApplicationCore &GetApplicationCore() { return m_Core; } protected: AAAApplicationCore &m_Core;};class DIAMETERBASEPROTOCOL_EXPORT AAASessionMessageHandler : public AAAEventHandler { public: AAASessionMessageHandler(AAAApplicationCore &appCore, AAACommandCode cmdCode) : AAAEventHandler(appCore), m_Code(cmdCode) { } AAACommandCode GetCommandCode() { return m_Code; } private: AAACommandCode m_Code;};class DIAMETERBASEPROTOCOL_EXPORT AAASession : public AAAEventHandler { public: typedef std::map<AAACommandCode, AAASessionMessageHandler*> AAAMessageMap; typedef std::pair<AAACommandCode, AAASessionMessageHandler*> AAAMessageMapPair; typedef enum { EVENT_AUTH_REQUEST = 0, /**< Application indicates pending authorization request */ EVENT_AUTH_SUCCESS, /**< Application indicates authorization successful */ EVENT_AUTH_CONTINUE, /**< Application indicates multi-round exchange */ EVENT_AUTH_FAILED, /**< Application indicates authorization successful */ EVENT_ACCT_SUCCESS, /**< Application indicates accounting request is successful */ EVENT_NO_SERVICE, /**< Application indicates service not provided */ EVENT_PROC_ERROR /**< Application indicates processing error */ } EVENT; public: AAASession(AAAApplicationCore &appCore, diameter_unsigned32_t appId) : AAAEventHandler(appCore), m_Id(appId), m_LastEvent(EVENT_AUTH_SUCCESS), m_IO(NULL) { } virtual ~AAASession() { } virtual AAAReturnCode SetTimeout(time_t timeout) { return (AAA_ERR_SUCCESS); } virtual AAAReturnCode RegisterMessageHandler (AAASessionMessageHandler *handler) { AAAMessageMap::iterator i = m_MsgMap.find (handler->GetCommandCode()); if (m_MsgMap.end() != i) { return (AAA_ERR_FAILURE); } m_MsgMap.insert(AAAMessageMapPair (handler->GetCommandCode(), handler)); return (AAA_ERR_SUCCESS); } virtual AAAReturnCode RemoveMessageHandler (AAASessionMessageHandler *handler) { AAAMessageMap::iterator i = m_MsgMap.find (handler->GetCommandCode()); if (m_MsgMap.end() != i) { m_MsgMap.erase(i); return (AAA_ERR_SUCCESS); } return (AAA_ERR_FAILURE); } virtual AAAReturnCode Update(AAASession::EVENT event) { m_LastEvent = event; return (AAA_ERR_SUCCESS); } const AAASessionHandle GetSessionHandle() { return (this); } diameter_unsigned32_t GetApplicationId() { return m_Id; } virtual void GetSessionId(diameter_octetstring_t &id) { } AAA_SessionIO *IO() { return m_IO; } protected: virtual AAAReturnCode CallMsgHandler(AAAMessage &msg) { AAAMessageMap::iterator i = m_MsgMap.find (msg.hdr.code); if (m_MsgMap.end() != i) { return i->second->HandleMessage(msg); } return (AAA_ERR_FAILURE); } protected: AAAMessageMap m_MsgMap; diameter_unsigned32_t m_Id; EVENT m_LastEvent; AAA_SessionIO *m_IO;};class DIAMETERBASEPROTOCOL_EXPORT AAAClientSession : public AAASession, public AAA_ClientAuthSession{ public: AAAClientSession(AAAApplicationCore &appCore, diameter_unsigned32_t id) : AAASession(appCore, id), AAA_ClientAuthSession(appCore.GetTask(), id) { m_IO = this; } virtual ~AAAClientSession() { AAA_ClientAuthSession::End(); } virtual AAAReturnCode SetTimeout(time_t timeout) { AAA_CFG_AUTH_SESSION()->lifetimeTm = (diameter_unsigned32_t)timeout; return (AAA_ERR_SUCCESS); } virtual void GetSessionId(diameter_octetstring_t &id) { char cbuf[128]; Attributes().SessionId().Dump(cbuf); id = cbuf; } AAAReturnCode Start() { return Begin(); } AAAReturnCode SetOptionalSIDValue(std::string optVal) { Attributes().SessionId().OptionalValue() = optVal.data(); return (AAA_ERR_SUCCESS); } AAAReturnCode End() { return AAA_ClientAuthSession::End(); } private: virtual AAAReturnCode RequestMsg(AAAMessage &msg) { return CallMsgHandler(msg); } virtual AAAReturnCode AnswerMsg(AAAMessage &msg) { return CheckUpdateEvent(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 AAAServerSession :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -