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

📄 sample_server5.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
        }        virtual void SetAuthGracePeriodTimeout        (AAA_ScholarAttribute<diameter_unsigned32_t> &timeout)        {            // optional override, called by the library so             // this server can dictate the auth grace period            // to the client. If not overridden, the value             // in the config file is used            timeout = 2;        }        virtual AAAReturnCode ReAuthenticate(diameter_unsigned32_t rcode) {            // optional override, called by the library so             // this server is informed that the client has            // responded to the server initiated re-auth            // request. The result code from the client            // is passed as a parameter to this funciton.            AAA_LOG(LM_INFO, "(%P|%t) **** client responded to re-auth ****\n");            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode RequestMsg(AAAMessage &msg) {            // all request 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) Request 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);            AAA_EnumAvpContainerWidget reAuthAvp(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);            diameter_enumerated_t *reAuth = reAuthAvp.GetAvp(AAA_AVPNAME_REAUTHREQTYPE);            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 (reAuth) {                AAA_LOG(LM_INFO, "(%P|%t) Re-Auth Request type: %d\n", *reAuth);	    }            // Send answer back            return TxAuthenticationAnswer();        }        virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {            // all answer messages are handled by this function.            // AAA servers normally will receive answer messages            // in the open state            // all answer messages are handled by this function.             // This function can retrun the following values:            // a. AAA_ERR_SUCCESS - client has successfully responded            //                      to server request            // b. AAA_ERR_FAILURE - client failed.             AAA_LOG(LM_INFO, "(%P|%t) **** Answer message message received in server ****\n");            AAA_MsgDump::Dump(msg);            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");            if (m_EndOnSuccess) {                End();	    }            else {                // test server re-auth                // ReAuth(AAA_SESSION_AUTHORIZE_AUTHENTICATE);	    }            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode Disconnect() {            // notification of completed STR/STA exchange            AAA_LOG(LM_INFO, "(%P|%t) **** session disconnecting ****\n");            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode SessionTimeout() {            // notification of session timeout            AAA_LOG(LM_INFO, "(%P|%t) **** session timeout ****\n");            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode AuthorizationTimeout() {            // notification of auth lifetime timeout            AAA_LOG(LM_INFO, "(%P|%t) **** auth timeout ****\n");            return (AAA_ERR_SUCCESS);        }        virtual AAAReturnCode AbortSession() {            // notification of completed ASR/ASA exchange            AAA_LOG(LM_INFO, "(%P|%t) **** session aborted by server ****\n");            return (AAA_ERR_SUCCESS);        }        AAAReturnCode TxAuthenticationAnswer() {            std::cout << "Sending answer message" << std::endl;            AAA_MsgWidget msg(300, false, 10000);            AAA_UInt32AvpWidget authIdAvp(AAA_AVPNAME_AUTHAPPID);            AAA_Utf8AvpWidget unameAvp(AAA_AVPNAME_USERNAME);            authIdAvp.Get() = 10000; // my application id            unameAvp.Get() = "username@domain.com";            msg()->acl.add(authIdAvp());            msg()->acl.add(unameAvp());            AAA_MsgResultCode rcode(*msg());            rcode.ResultCode(AAA_SUCCESS);            Send(msg());            return (AAA_ERR_SUCCESS);        }    private:        bool m_EndOnSuccess;};// Server session factory. Unlike AAA clients, server// sessions need to be created on demand. This factory// is responsible for creating new server sessions// based on incomming new request.typedef AAA_ServerSessionAllocator<AAA_SampleAuthServer>         SampleAuthServerAllocator;typedef AAA_ServerSessionAllocator<AAA_SampleAcctServer>         SampleAcctServerAllocator;int main(int argc, char *argv[]){   AAA_Task task;   task.Start(5);   // Application core is responsible for providing   // peer connectivity between AAA entities   AAA_Application appCore(task, "config/isp.local.xml");   SampleAuthServerAllocator auth(task, 10000);   SampleAcctServerAllocator acct(task, 20000);   appCore.RegisterServerSessionFactory(auth);   appCore.RegisterServerSessionFactory(acct);   while (true) {      std::cout << "Just wait here and let factory take care of new sessions" << std::endl;      ACE_OS::sleep(10);   }   appCore.Close();   task.Stop();   return (0);}

⌨️ 快捷键说明

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