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

📄 aaa_session_client.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* 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                                                          */#include "aaa_session_db.h"#include "aaa_session_client.h"AAA_ClientAuthSession::~AAA_ClientAuthSession(){    if (m_Fsm.IsRunning()) {       Reset();    } }AAAReturnCode AAA_ClientAuthSession::Begin(char *optionValue){    // re-negotiate the following values    Attributes().SessionTimeout().IsNegotiated() = false;    Attributes().AuthLifetime().IsNegotiated() = false;    Attributes().AuthGrace().IsNegotiated() = false;    // session lifetime values    AAA_ScholarAttribute<diameter_unsigned32_t> sessTout;    sessTout() = AAA_CFG_AUTH_SESSION()->sessionTm;    SetSessionTimeout(sessTout);    if (sessTout.IsSet()) {        Attributes().SessionTimeout() = sessTout();    }    // auth lifetime values    AAA_ScholarAttribute<diameter_unsigned32_t> authLifetime;    authLifetime() = AAA_CFG_AUTH_SESSION()->lifetimeTm;    SetAuthLifetimeTimeout(authLifetime);    if (authLifetime.IsSet()) {        Attributes().AuthLifetime() = authLifetime();    }    // sanity checks    if (Attributes().AuthLifetime()() >         Attributes().SessionTimeout()()) {        int holder = Attributes().SessionTimeout()() - 1;        Attributes().AuthLifetime() = (holder >= 0) ? holder : holder + 1;         AAA_LOG(LM_INFO, "(%P|%t) !!! WARNING !!! application sets authorization lifetime\n");        AAA_LOG(LM_INFO, "(%P|%t)                 to be greater than session timeout, overriding to %d\n",                Attributes().AuthLifetime()());    }    // grace period values    AAA_ScholarAttribute<diameter_unsigned32_t> gracePeriod;    gracePeriod() = AAA_CFG_AUTH_SESSION()->graceTm;    SetAuthGracePeriodTimeout(gracePeriod);    if (gracePeriod.IsSet()) {        Attributes().AuthGrace() = gracePeriod();    }    // check for re-start    if (! m_Fsm.IsRunning()) {        // session state values        AAA_ScholarAttribute<diameter_unsigned32_t> authState;        authState() = AAA_CFG_AUTH_SESSION()->stateful;        SetAuthSessionState(authState);        if (authState.IsSet()) {            Attributes().AuthSessionState() = authState();        }        // assign diameter id        std::string &id = Attributes().SessionId().DiameterId();        id = AAA_CFG_TRANSPORT()->identity + ".";        id += AAA_CFG_TRANSPORT()->realm;        if (optionValue) {            Attributes().SessionId().OptionalValue() = optionValue;        }        // add to session database        AAA_SESSION_DB().Add(Attributes().SessionId(), *this);        Attributes().SessionId().Dump();        // run the fsm        m_Fsm.Start();    }    if (ReStart() == AAA_ERR_SUCCESS) {        m_Fsm.Notify(AAA_SESSION_AUTH_EV_REQUEST_ACCESS);    }    else {        m_Fsm.Stop();    }    return (AAA_ERR_SUCCESS);}void AAA_ClientAuthSession::RxRequest(std::auto_ptr<AAAMessage> msg) {    // base protocol request message filters    if ((msg->hdr.code == AAA_MSGCODE_ABORTSESSION) &&        (Attributes().AuthSessionState() == AAA_SESSION_STATE_MAINTAINED)) {        m_Fsm.RxASR(*msg);        if (AbortSession() == AAA_ERR_SUCCESS) {            m_Fsm.Notify(AAA_SESSION_AUTH_EV_RX_ASR_OK);        }        else {            m_Fsm.Notify(AAA_SESSION_AUTH_EV_RX_ASR_RETRY);        }    }    else if (msg->hdr.code == AAA_MSGCODE_SESSIONTERMINATION) {        AAA_LOG(LM_DEBUG,"(%P|%t) *** STR received in client session, discarding\n");    }    else if (msg->hdr.code == AAA_MSGCODE_REAUTH) {        m_Fsm.RxRAR(*msg);        AAA_UInt32AvpContainerWidget reAuthTypeAvp(msg->acl);        diameter_unsigned32_t *reAuthType = reAuthTypeAvp.GetAvp(AAA_AVPNAME_REAUTHREQTYPE);        if (reAuthType) {           AAA_ReAuthValue value = { 0, *reAuthType };           Attributes().ReAuthRequestValue() = value;           m_Fsm.Notify(AAA_SESSION_AUTH_EV_RX_RAR);        }        else {           AAA_LOG(LM_INFO, "(%P|%t) Re-Auth request received with no re-auth-type\n");           Attributes().ReAuthRequestValue().Clear();	}    }    else {        m_Fsm.Notify(AAA_SESSION_AUTH_EV_RX_SSAR, msg);    }}void AAA_ClientAuthSession::RxAnswer(std::auto_ptr<AAAMessage> msg) {    // base protocol answer message filters    if (msg->hdr.code == AAA_MSGCODE_SESSIONTERMINATION) {        if (Attributes().AuthSessionState() ==             AAA_SESSION_STATE_MAINTAINED) {            m_Fsm.RxSTA(*msg);            m_Fsm.Notify(AAA_SESSION_AUTH_EV_RX_STA);        }        return;    }    else if (msg->hdr.code == AAA_MSGCODE_ABORTSESSION) {        AAA_LOG(LM_DEBUG,"(%P|%t) *** ASA received in client session, discarding\n");        return;    }    if (! Attributes().AuthSessionState().IsNegotiated()) {        AAA_EnumAvpContainerWidget sessionStateAvp(msg->acl);        diameter_enumerated_t *state = sessionStateAvp.GetAvp            (AAA_AVPNAME_AUTHSESSIONSTATE);        if (state) {            Attributes().AuthSessionState().Set(*state);            AAA_LOG(LM_INFO, "(%P|%t) Server dictated session state: %d\n",                     Attributes().AuthSessionState()());        }    }    if (! Attributes().SessionTimeout().IsNegotiated()) {        AAA_UInt32AvpContainerWidget timeoutAvp(msg->acl);        diameter_unsigned32_t *tout = timeoutAvp.GetAvp            (AAA_AVPNAME_SESSIONTIMEOUT);        if (tout) {            Attributes().SessionTimeout().Set(*tout);            AAA_LOG(LM_INFO, "(%P|%t) Server dictated session timeout: %d\n",                     Attributes().SessionTimeout()());        }    }    if (! Attributes().AuthLifetime().IsNegotiated()) {        AAA_UInt32AvpContainerWidget lifetimeAvp(msg->acl);        diameter_unsigned32_t *tout = lifetimeAvp.GetAvp            (AAA_AVPNAME_AUTHLIFETIME);        if (tout) {            Attributes().AuthLifetime().Set(*tout);            AAA_LOG(LM_INFO, "(%P|%t) Server dictated auth lifetime: %d\n",                     Attributes().AuthLifetime()());        }    }    if (! Attributes().AuthGrace().IsNegotiated()) {        AAA_UInt32AvpContainerWidget graceAvp(msg->acl);        diameter_unsigned32_t *tout = graceAvp.GetAvp            (AAA_AVPNAME_AUTHGRACE);        if (tout) {            Attributes().AuthGrace().Set(*tout);            AAA_LOG(LM_INFO, "(%P|%t) Server dictated grace period: %d\n",                     Attributes().AuthGrace()());        }    }    m_Fsm.Notify(AAA_SESSION_AUTH_EV_RX_SSAA, msg);}void AAA_ClientAuthSession::RxError(std::auto_ptr<AAAMessage> msg) {    ErrorMsg(*msg);}AAAReturnCode AAA_ClientAuthSession::RxDelivery(std::auto_ptr<AAAMessage> msg){    typedef struct {        AAAReturnCode m_Rc;        AAA_Event m_AnsEvent;        AAA_Event m_ReqEvent;        bool m_StatefulOnly;        bool m_ValidOnRequestMsg;    } RxHandler;    static RxHandler RxHandlerAry[] = {        { AAA_ERR_INCOMPLETE, 0,           0, false, false },        { AAA_ERR_SUCCESS, AAA_SESSION_AUTH_EV_SSAA_OK, 

⌨️ 快捷键说明

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