📄 sample_client5.cxx
字号:
/* 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 #include "diameter_api.h"class AAA_SampleClientAcctRecCollector : public AAA_ClientAcctRecCollector{ public: virtual void GenerateRecord(AAAAvpContainerList &avpList, int recordType, int recordNum) { /// Called by the library to ask the client application /// to generate records that will be stored in vendor /// specific AVP's. These avp's will then be added to /// the avpList before sending the ACR /// Note that Example-Accounting-Record AVP is appended /// to the ACR dictionary definition in dictionary.xml. /// Real applications may also need to append Vendor- /// Specific-Application-Id here AAA_Utf8AvpWidget recAvp("Example-Accounting-Record"); recAvp.Get() = "My example record should show up in the server"; avpList.add(recAvp()); } virtual bool IsLastRecordInStorage() { /// Checks the client app if there is a a record /// that has temporarily been stored due to prior /// transmission failure. The check should be /// based on application specific storage return (false); } virtual bool IsStorageSpaceAvailable() { /// Checks the client app if it will be able /// to store a record in case transmission /// fails. return (true); } virtual AAAReturnCode StoreLastRecord(int recordType) { /// Asks the client app to temporarily /// store the last known record. This maybe /// due to transmission and the library is /// attempting to retry. Applications MUST /// provide thier own storage here return (AAA_ERR_SUCCESS); } virtual AAAReturnCode DeleteLastRecord(int recordType) { /// Asks the client app to delete the /// last temporarily stored record if any return (AAA_ERR_SUCCESS); }};class AAA_SampleClientAcctSubSession : public AAA_ClientAcctSubSession<AAA_SampleClientAcctRecCollector> { // AAA client session derived from AAA_ClientAcctSession. // It provides for all the functionality of a diameter // client accounting session. The ClientAcctSubSession // class is a template function that requires a proper // version of a record collector as a paramter. Note // that the application is responsible for instantiating // this object public: AAA_SampleClientAcctSubSession(AAA_ClientAcctSession &parent) : AAA_ClientAcctSubSession<AAA_SampleClientAcctRecCollector>(parent), m_IsComplete(false) { } 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"; } /// This function is used for setting realtime required /// AVP as a hint to the server virtual void SetRealTimeRequired (AAA_ScholarAttribute<diameter_enumerated_t> &rt) { } /// This function is used for setting acct interim /// interval AVP as a hint to the server virtual void SetInterimInterval (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout) { } /// This function is used for setting RADIUS acct /// session id for RADIUS/DIAMETER translations virtual void SetRadiusAcctSessionId (AAA_ScholarAttribute<diameter_octetstring_t> &sid) { } /// This function is used for setting multi-session /// id AVP virtual void SetMultiSessionId (AAA_ScholarAttribute<diameter_utf8string_t> &sid) { } virtual AAAReturnCode Success() { // notification of successful ACR exchange for all record type AAA_LOG(LM_INFO, "(%P|%t) **** record exchange completed ****\n"); m_IsComplete = true; return (AAA_ERR_SUCCESS); } virtual AAAReturnCode Failed(int recNum) { // notification that recNum record was not processed properly AAA_LOG(LM_INFO, "(%P|%t) **** record #%d not processed ****\n", recNum); m_IsComplete = true; return (AAA_ERR_SUCCESS); } bool IsComplete() { return m_IsComplete; } private: bool m_IsComplete;};class AAA_SampleAcctClient : public AAA_ClientAcctSession{ // AAA client session derived from AAA_ClientAcctSession. // It provides for all the functionality of a diameter // client accounting session. The ClientAcctSubSession // class is a template function that requires a proper // version of a record collector as a paramter. Note // that the application is responsible for instantiating // this object public: AAA_SampleAcctClient(AAA_Task &task, diameter_unsigned32_t id) : AAA_ClientAcctSession(task, id), m_AcctSubSession(*this) { // sub-session uses parent } void SendEventRecord() { m_AcctSubSession.Begin(true); } bool IsComplete() { return m_AcctSubSession.IsComplete(); } protected: // Accounting sub-session AAA_SampleClientAcctSubSession m_AcctSubSession;};class AAA_SampleAuthClient : public AAA_ClientAuthSession{ public: AAA_SampleAuthClient(AAA_Task &task, diameter_unsigned32_t authId, diameter_unsigned32_t acctId, int howManyMsg = 1) : AAA_ClientAuthSession(task, authId), m_AcctSession(task, acctId), m_HowManyMsg(howManyMsg), 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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -