📄 diameter_mip4_fa_client_session.hxx
字号:
/* BEGIN_COPYRIGHT *//* *//* OpenDiameter: Open-source software for the Diameter protocol *//* *//* Copyright (C) 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 *//* diameter_mip4_fa_client_session.hxx Fa Client Session definition for Diameter MIP 4 Application Written by Miriam Tauil Created January 19, 2005.*/#ifndef __MIP4_FA_CLIENT_SESSION_H__#define __MIP4_FA_CLIENT_SESSION_H__#include <list>#include "ace/Synch.h"#include "diameter_api.h"#include "diameter_mip4_fa_client_fsm.hxx"#include "diameter_mip4_parser.hxx"#include "mip4_diameter_fa_client_interface.hxx"/// Diameter MIP FA Client session. This class is defined as multiple/// inheritance, from AAAClientSession (defined in Diameter API),/// DiameterMip4FaClientStateMachine and the abstract interface/// Mip4DiameterFaClientInterfacetemplate<class SpecificFaClientSession > class DiameterMip4FaClientSession : public AAAClientSession, public DiameterMip4FaClientStateMachine, public Mip4DiameterFaClientInterface{ public: class DIAMETER_MIP4_FA_CLIENT_EXPORTS AMA_Handler : public AAASessionMessageHandler { public: AMA_Handler(AAAApplicationCore &appCore, DiameterMip4FaClientSession<SpecificFaClientSession> &s) : AAASessionMessageHandler(appCore, MipAmrCommandCode), session(s) {} private: DiameterMip4FaClientSession<SpecificFaClientSession> &session; AAAReturnCode HandleMessage (AAAMessage &msg) { // Header flag check. if (msg.hdr.flags.r) { AAA_LOG(LM_ERROR, "[%N] Received AMR instead of AMA.\n"); return AAA_ERR_UNKNOWN_CMD; } // Parse the received message. AMA_Parser parser; parser.setAppData(&session.amaData); parser.setRawData(&msg); try { parser.parseRawToApp(); } catch ( DiameterParserError ) { AAA_LOG(LM_ERROR, "[%N] Payload error.\n"); return AAA_ERR_PARSING_ERROR; } session.Notify(DiameterMip4FaClientStateMachine::EvRxAMA); return AAA_ERR_SUCCESS; } }; /// Constuctor. DiameterMip4FaClientSession(AAAApplicationCore &appCore): AAAClientSession(appCore, Mip4ApplicationId), DiameterMip4FaClientStateMachine(*this, appCore.GetTask().JobHandle()), specificFaClientSession(*new SpecificFaClientSession(*this)) { answerHandler = (new AMA_Handler(appCore, *this)); // Register the AMA message handler if (RegisterMessageHandler( answerHandler) != AAA_ERR_SUCCESS) { AAA_LOG(LM_ERROR, "[%N] AMA_Handler registration failed.\n"); throw -1; } // test if SpecificFaClientSession is an FaClientSession#ifdef THIS_SHOULD_WORK_BUT_IT_DOESNT try { FaClientSession &faClientSession = dynamic_cast<FaClientSession&>(specificFaClientSession); assert (faClientSession != NULL); } catch (bad_cast) { DIAMETER_LOG(LM_ERROR, "[%N] AMA_Handler registration failed.\n"); throw -1; } #endif} /// Destructor. virtual ~DiameterMip4FaClientSession() { delete (&specificFaClientSession); delete answerHandler; } // this is a virtual fn in the parent interface, that must be implemented // here. void RxMipRegReq( diameter_octetstring_t &mipRegReq) { amrData.MipRegRequest.Set( mipRegReq); Notify( DiameterMip4FaClientStateMachine::EvRxMipRegReq); } DiameterMip4FaClientSession* Self() { return this; } /// Reimplemented from AAAClientSession. This is invoked during /// incomming message events. The msg argument is pre-allocated by /// the library and is valid only within the context of this /// method. It is the responsibility of the derived class to /// override this function and capture the events if it is /// interested in it. AAAReturnCode HandleMessage(AAAMessage &msg) { AAA_LOG(LM_ERROR, "[%N] Unknown command.\n"); return AAA_ERR_UNKNOWN_CMD; } /// Reimplemented from AAAClientSession. This is invoked during /// session disconnect event. Disconnection occurs when a session is /// terminated or the peer connection is disconnection and unable to /// recover. It is the responsibility of the derived class to /// override this function and capture this events if it is /// interested in it. AAAReturnCode HandleDisconnect() { AAA_LOG(LM_ERROR, "[%N] Session termination event received.\n"); Notify(DiameterMip4FaClientStateMachine::EvSgDisconnect); return AAA_ERR_SUCCESS; } /// Reimplemented from AAAClientSession. AAAReturnCode HandleSessionTimeout() { AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n"); Notify(DiameterMip4FaClientStateMachine::EvSgSessionTimeout); return AAA_ERR_SUCCESS; } /// Reimplemented from AAAClientSession. AAAReturnCode HandleAuthLifetimeTimeout() { AAA_LOG(LM_ERROR, "[%N] Timeout received.\n"); Notify(DiameterMip4FaClientStateMachine::EvSgAuthLifetimeTimeout); return AAA_ERR_SUCCESS; } /// Reimplemented from AAAClientSession. AAAReturnCode HandleAuthGracePeriodTimeout() { AAA_LOG(LM_ERROR, "[%N] Timeout received.\n"); Notify(DiameterMip4FaClientStateMachine::EvSgAuthGracePeriodTimeout); return AAA_ERR_SUCCESS; } /// Reimplemented from AAAClientSession. This is invoked during /// session timeout event. Timeout occurs when a session is idle /// (not re- authorization) for a specified amount of time. It is /// the responsibility of the derived class to override this /// function and capture this events if it is interested in it. AAAReturnCode HandleTimeout() { AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n"); Notify(DiameterMip4FaClientStateMachine::EvSgTimeout); return AAA_ERR_SUCCESS; } /// Reimplemented from AAAClientSession. This is invoked during /// session abort event. Abort occurs when the server decides to /// terminate the client session by sending an ASR. It is the /// responsibility of the derived class to override this function /// and capture this events if it is interested in it. AAAReturnCode HandleAbort() { return AAA_ERR_SUCCESS; } void Start() throw (AAA_Error) { DiameterMip4FaClientStateMachine::Start(); AAAClientSession::Start(); } AAAReturnCode Reset() throw (AAA_Error) { AAAClientSession::Start(); amrData.Clear(); amaData.Clear(); //sets the session state to StInitialize DiameterMip4FaClientStateMachine::Restart(); specificFaClientSession.Reset(); return AAA_ERR_SUCCESS; } // The implementation of this function in a child class is optional. // The function's purpose is to provide an interface for memory deallocation // of the DiameterMip4FaClientSession, when it is allocated using the "new" // operator. More documentation in the sample application file. virtual void Abort(){} void SetUserName(AAA_ScholarAttribute<diameter_utf8string_t> &userName) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -