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

📄 sample_client5.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
        {            // 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 = 30;        }        virtual void SetAuthLifetimeTimeout        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)        {            // optional override, called by the library so             // this client can send a hint to the server             // about the auth lifetime it prefers. If not            // overridden, the value in the config file            // is used            timeout = 29;        }        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.             // 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");            AAA_MsgDump::Dump(msg);            AAA_IdentityAvpContainerWidget oHostAvp(msg.acl);            AAA_IdentityAvpContainerWidget oRealmAvp(msg.acl);            AAA_Utf8AvpContainerWidget uNameAvp(msg.acl);            AAA_UInt32AvpContainerWidget authAppIdAvp(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);            }            if ((-- m_HowManyMsg) > 0) {		TxAuthenticationRequest();                return (AAA_ERR_INCOMPLETE);	    }            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {            // all error messages are handled by this function.            AAA_LOG(LM_INFO, "(%P|%t) **** Received message with error bit set ****\n");            return (AAA_ERR_SUCCESS);	}        virtual AAAReturnCode Success() {            // notification of successful auth            AAA_LOG(LM_INFO, "(%P|%t) **** user authorized ****\n");            // send an event record            m_AcctSession.SendEventRecord();            m_Success = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode Disconnect() {            // notification of completed STR/STA exchange            AAA_LOG(LM_INFO, "(%P|%t) **** session disconnecting ****\n");            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode SessionTimeout() {            // notification of session timeout            AAA_LOG(LM_INFO, "(%P|%t) **** session timeout ****\n");            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode AuthorizationTimeout() {            // notification of auth lifetime timeout            AAA_LOG(LM_INFO, "(%P|%t) **** auth timeout ****\n");            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode AbortSession() {            // notification of completed ASR/ASA exchange            AAA_LOG(LM_INFO, "(%P|%t) **** session aborted by server ****\n");            m_Disconnected = true;            return (AAA_ERR_SUCCESS);        }        AAAReturnCode TxAuthenticationRequest() {            std::cout << "Sending request message" << std::endl;            // sample of how to compose a message using parser widgets            AAA_MsgWidget msg(300, true, 10000);            AAA_UInt32AvpWidget authIdAvp(AAA_AVPNAME_AUTHAPPID);            AAA_Utf8AvpWidget unameAvp(AAA_AVPNAME_USERNAME);            AAA_EnumAvpWidget reAuthAvp(AAA_AVPNAME_REAUTHREQTYPE);            authIdAvp.Get() = 10000; // my application id            unameAvp.Get() = "username@domain.com";            reAuthAvp.Get() = 1;            msg()->acl.add(authIdAvp());            msg()->acl.add(unameAvp());            msg()->acl.add(reAuthAvp());            Send(msg());            return (AAA_ERR_SUCCESS);        }        bool UserAuthorized() {            return m_Success;	}        bool SessionDisconnected() {            return (m_Disconnected && m_AcctSession.IsComplete());	}    protected:        AAA_SampleAcctClient m_AcctSession;    private:        int m_HowManyMsg;        bool m_Success;        bool m_Disconnected;};int main(int argc, char *argv[]){   AAA_Task task;   task.Start(5);   int msgCountPerSession = 1;   char *cfgFile = "config/nas1.local.xml";   if (argc == 2) {       cfgFile = argv[1];   }   else if (argc == 3) {       cfgFile = argv[1];       msgCountPerSession = (atoi(argv[2]) > 0) ? 	      atoi(argv[2]) : msgCountPerSession;   }   else if (argc > 2) {       std::cout << "Usage: aaa_sample_client2 [config file] [num message]\n"                  << std::endl;       exit(0);   }   // Application core is responsible for providing   // peer connectivity between AAA entities   AAA_Application appCore(task);   if (appCore.Open(cfgFile) == AAA_ERR_SUCCESS) {       /// Wait for connectivity       do {           std::cout << "Waiting till this AAA has connectivity" << std::endl;           ACE_OS::sleep(1);       } while (appCore.NumActivePeers() == 0);       /// send the client request       AAA_SampleAuthClient client(task, 10000, 20000, msgCountPerSession);       client.Begin("my_client");       client.TxAuthenticationRequest();       do {           std::cout << "Waiting till user is authorized " << std::endl;           ACE_OS::sleep(1);       } while (! client.UserAuthorized());       client.End();       do {           std::cout << "Waiting till user is disconnected " << std::endl;           ACE_OS::sleep(1);       } while (! client.SessionDisconnected());   }   appCore.Close();   task.Stop();   return (0);}

⌨️ 快捷键说明

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