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

📄 sample_client3.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                                                          */// victor fajardo: sample client using message mux and multiple session#include "diameter_api.h"#include "aaa_session_msg_mux.h"class AAA_SampleClient : public AAA_ClientAuthSession,                         public AAA_SessionMsgMux<AAA_SampleClient>{        // AAA client session derived from AAA_ClientAuthSession        // and an AAA_SessionMsgMux<>. The message mux allows         // message delegation to registered message handlers.        // The client session is the same as in sample_client2.cxx.    public:        AAA_SampleClient(AAA_Task &task,                         diameter_unsigned32_t id,                         int number) :            AAA_ClientAuthSession(task, id),            AAA_SessionMsgMux<AAA_SampleClient>(*this),            m_SessionNum(number),            m_Success(false),            m_Disconnected(false) {        }        virtual void SetAuthSessionState        (AAA_ScholarAttribute<diameter_unsigned32_t> &authState)        {            // optional override, called by the library to set             // the auth state. Note that this overrides the             // settings in the configuration file or applications             // sending an auth session state AVP            authState = AAA_SESSION_STATE_MAINTAINED;        }        virtual void SetDestinationHost        (AAA_ScholarAttribute<diameter_identity_t> &dHost)        {            // optional override, called by the library to             // set the destination host. Note that this             // overrides applications sending a destination            // host AVP            dHost = "server.isp.net";        }        virtual void SetDestinationRealm        (AAA_ScholarAttribute<diameter_identity_t> &dRealm)        {            // optional override, called by the library             // to set the destination realm. Note that             // this overrides applications sending a             // destination realm AVP            dRealm = "isp.net";        }        virtual void SetSessionTimeout        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)        {            // optional override, called by the library so             // this client can send a hint to the server             // about the session timeout it prefers. If not            // overridden, the value in the config file            // is used            timeout = 5;        }        virtual AAAReturnCode ReAuthenticate(diameter_unsigned32_t type) {            // optional override, called by the library so             // this client is informed about a re-auth request            // initiated by the server. Note that the client            // must return a valid result-code when exiting            // this function            AAA_LOG(LM_INFO, "(%P|%t) **** server re-authentication ****\n");            return (AAAReturnCode)(AAA_SUCCESS);        }        virtual AAAReturnCode RequestMsg(AAAMessage &msg) {            // all request messages are handled by this function.            // AAA clients normally will receive request message            // in the open state            // all request messages are handled by this function.             // This function can retrun the following values:            // a. AAA_ERR_SUCCESS - client is successfully responded            //                      to server request            // b. AAA_ERR_FAILURE - client failed.             AAA_LOG(LM_INFO, "(%P|%t) **** Request message message received in client ****\n");            AAA_MsgDump::Dump(msg);            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {            // all answer messages are handled by this function.            // Note that you can call the Mux() method            // here to deligate handling of messages. See            // sample_client2.cxx and comments below in the            // AnswerMsg() of the mux message handler            return Mux(msg);        }        virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {            // all error messages are handled by this function.            AAA_LOG(LM_INFO, "(%P|%t) **** [Num:%d] Received message with error bit set ****\n",                    m_SessionNum);            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode Success() {            // notification of successful auth            AAA_LOG(LM_INFO, "(%P|%t) **** [Num:%d] user authorized ****\n",                    m_SessionNum);            m_Success = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode Disconnect() {            // notification of completed STR/STA exchange            AAA_LOG(LM_INFO, "(%P|%t) **** [Num:%d] session disconnecting ****\n",                    m_SessionNum);            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode SessionTimeout() {            // notification of session timeout            AAA_LOG(LM_INFO, "(%P|%t) **** [Num:%d] session timeout ****\n",                    m_SessionNum);            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode AuthorizationTimeout() {            // notification of auth lifetime timeout            AAA_LOG(LM_INFO, "(%P|%t) **** [Num:%d] auth timeout ****\n",                    m_SessionNum);            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode AbortSession() {            // notification of completed ASR/ASA exchange            AAA_LOG(LM_INFO, "(%P|%t) **** [Num:%d] session aborted by server ****\n",                    m_SessionNum);            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        bool UserAuthorized() {            return m_Success;        }        bool SessionDisconnected() {            return m_Disconnected;        }        int SessionNum() {            return m_SessionNum;        }    private:        int m_SessionNum;        bool m_Success;        bool m_Disconnected;};class AAA_SampleClientAction :     public AAA_SessionMsgMuxHandler<AAA_SampleClient>{        // AAA message multiplex handler. This is a        // handler class for a specific AAA message.        // and instance of this class is registered        // with an AAA_SessionMsgMux<> object    public:        AAA_SampleClientAction(int howManyMsg = 1) :            m_HowManyMsg(howManyMsg) {        }        virtual AAAReturnCode AnswerMsg(AAA_SampleClient &client, AAAMessage &msg) {            // all answer messages with code 300 are handled by            // this function. This function can retrun the following            // values:            // a. AAA_ERR_SUCCESS - client is successfully authenticated            // b. AAA_ERR_INCOMPLETE - auth not yet completed, muti-round             //                         message trip exchange            // c. AAA_ERR_FAILURE - client authentication failed            AAA_LOG(LM_INFO, "(%P|%t) Answer message received\n");#if 0            AAA_MsgDump::Dump(msg);            AAA_IdentityAvpContainerWidget oHostAvp(msg.acl);            AAA_IdentityAvpContainerWidget oRealmAvp(msg.acl);            AAA_Utf8AvpContainerWidget uNameAvp(msg.acl);            AAA_UInt32AvpContainerWidget authAppIdAvp(msg.acl);            AAA_GroupedAvpContainerWidget tunneling(msg.acl);            diameter_identity_t *host = oHostAvp.GetAvp(AAA_AVPNAME_ORIGINHOST);            diameter_identity_t *realm = oRealmAvp.GetAvp(AAA_AVPNAME_ORIGINREALM);            diameter_utf8string_t *uname = uNameAvp.GetAvp(AAA_AVPNAME_USERNAME);            diameter_unsigned32_t *authAppId = authAppIdAvp.GetAvp(AAA_AVPNAME_AUTHAPPID);            if (host) {                AAA_LOG(LM_INFO, "(%P|%t) From Host: %s\n", host->data());            }            if (realm) {                AAA_LOG(LM_INFO, "(%P|%t) From Realm: %s\n", realm->data());            }            if (uname) {                AAA_LOG(LM_INFO, "(%P|%t) From User: %s\n", uname->data());            }            if (authAppId) {                AAA_LOG(LM_INFO, "(%P|%t) Auth Application Id: %d\n", *authAppId);            }

⌨️ 快捷键说明

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