📄 sample_server1.cxx
字号:
*/ AAAMessageControl msgControl(this); msgControl.SetResultCode(acaMsg, request, AAA_SUCCESS); if (msgControl.Send(acaMsg) != AAA_ERR_SUCCESS) { ACE_ERROR((LM_ERROR, "(%P|%t) Server: Failed sending message\n")); return (AAA_ERR_FAILURE); } else { ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Sent Auth Message\n")); } return (AAA_ERR_SUCCESS);}AAASampleAccountingServer::AAASampleAccountingServer(AAAApplicationCore &appCore, diameter_unsigned32_t appId) : AAAAccountingServerSession(appCore, appId), xml(*this){ // we assign the instance of our XML transformer // to the base class so it can invoke it when // needed SetTransformer(&xml);}AAASampleAccountingServer::~AAASampleAccountingServer(){ // do nothing}AAAReturnCode AAASampleAccountingServer::SendAcctAnswer(AAAMessage &request){ /* * Sample accounting request. This message * composition follows libdiamparser rules in * composing an AAAMessage. The commandn code * for accounting request is AAASampleAccountingRequestMsg::ACR. */ ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Sending test acct answer message\n")); AAAAvpContainerManager cm; AAAAvpContainerEntryManager em; AAAAvpContainer *c_sessId = cm.acquire("Session-Id"); AAAAvpContainer *c_orhost = cm.acquire("Origin-Host"); AAAAvpContainer *c_orrealm = cm.acquire("Origin-Realm"); AAAAvpContainer *c_drealm = cm.acquire("Destination-Realm"); AAAAvpContainer *c_rectype = cm.acquire("Accounting-Record-Type"); AAAAvpContainer *c_recnum = cm.acquire("Accounting-Record-Number"); AAAAvpContainer *c_acctid = cm.acquire("Accounting-Application-Id"); AAAAvpContainer *c_user = cm.acquire("User-Name"); AAAAvpContainer *c_subid = cm.acquire("Accounting-Sub-Session-Id"); AAAAvpContainer *c_acctsid = cm.acquire("Accounting-Session-Id"); AAAAvpContainer *c_acctmsid = cm.acquire("Acct-Multi-Session-Id"); AAAAvpContainer *c_intvl = cm.acquire("Accounting-Interim-Interval"); AAAAvpContainer *c_realtime = cm.acquire("Accounting-Realtime-Required"); AAAAvpContainer *c_origin = cm.acquire("Origin-State-Id"); AAAAvpContainerEntry *e; e = em.acquire(AAA_AVP_UTF8_STRING_TYPE); c_sessId->add(e); e = em.acquire(AAA_AVP_DIAMID_TYPE); c_orhost->add(e); e = em.acquire(AAA_AVP_DIAMID_TYPE); c_orrealm->add(e); e = em.acquire(AAA_AVP_DIAMID_TYPE); c_drealm->add(e); e = em.acquire(AAA_AVP_UINTEGER32_TYPE); diameter_unsigned32_t &rectyp = e->dataRef(Type2Type<diameter_unsigned32_t>()); c_rectype->add(e); e = em.acquire(AAA_AVP_UINTEGER32_TYPE); diameter_unsigned32_t &recnum = e->dataRef(Type2Type<diameter_unsigned32_t>()); c_recnum->add(e); e = em.acquire(AAA_AVP_INTEGER32_TYPE); diameter_integer32_t &acctid = e->dataRef(Type2Type<diameter_integer32_t>()); c_acctid->add(e); e = em.acquire(AAA_AVP_UTF8_STRING_TYPE); diameter_utf8string_t &user = e->dataRef(Type2Type<diameter_utf8string_t>()); c_user->add(e); e = em.acquire(AAA_AVP_UINTEGER64_TYPE); diameter_unsigned64_t &subid = e->dataRef(Type2Type<diameter_unsigned64_t>()); c_subid->add(e); e = em.acquire(AAA_AVP_STRING_TYPE); diameter_octetstring_t &acctsid = e->dataRef(Type2Type<diameter_octetstring_t>()); c_acctsid->add(e); e = em.acquire(AAA_AVP_UTF8_STRING_TYPE); diameter_utf8string_t &acctmsid = e->dataRef(Type2Type<diameter_utf8string_t>()); c_acctmsid->add(e); e = em.acquire(AAA_AVP_UINTEGER32_TYPE); diameter_unsigned32_t &intvl = e->dataRef(Type2Type<diameter_unsigned32_t>()); c_intvl->add(e); e = em.acquire(AAA_AVP_UINTEGER32_TYPE); diameter_unsigned32_t &realtime = e->dataRef(Type2Type<diameter_unsigned32_t>()); c_realtime->add(e); e = em.acquire(AAA_AVP_UINTEGER32_TYPE); diameter_unsigned32_t &origin = e->dataRef(Type2Type<diameter_unsigned32_t>()); c_origin->add(e); AAAMessage acctMsg; hdr_flag flag = {0,0,0,0,0}; AAADiameterHeader h(0, 0, flag, AAASampleAccountingServer::ACR, 20000, 0, 0); acctMsg.hdr = h; acctMsg.acl.add(c_sessId); acctMsg.acl.add(c_orhost); acctMsg.acl.add(c_orrealm); acctMsg.acl.add(c_drealm); acctMsg.acl.add(c_rectype); acctMsg.acl.add(c_recnum); acctMsg.acl.add(c_acctid); acctMsg.acl.add(c_user); acctMsg.acl.add(c_subid); acctMsg.acl.add(c_acctsid); acctMsg.acl.add(c_acctmsid); acctMsg.acl.add(c_intvl); acctMsg.acl.add(c_realtime); acctMsg.acl.add(c_origin); rectyp = 1; // event record only recnum = 0; acctid = 0; // sample only user.assign("sample user"); subid = 0; // sample only acctsid.assign("sample sid"); acctmsid.assign("sample multi sid"); intvl = 30; // 30 sec interval for sampling realtime = 2; // grant and store origin = 0; // sample only /* * The use of AAAMessageControl is shown here. * It is a utility class used in sending messages * via the local session object as well as setting * the result code. */ AAAMessageControl msgControl(this); msgControl.SetResultCode(acctMsg, request, AAA_SUCCESS); if (msgControl.Send(acctMsg) != AAA_ERR_SUCCESS) { ACE_ERROR((LM_ERROR, "(%P|%t) Server: Failed sending message\n")); return (AAA_ERR_FAILURE); } else { ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Sent Acct Message\n")); } return (AAA_ERR_SUCCESS);}AAAReturnCode AAASampleXMLTrans::OutputRecord(AAAMessage *originalMsg){ ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Accounting transformer successfully converted record\n")); if (record) { ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Record Size: %d\n", record_size)); ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Record: %s\n", (char*)record)); /* * Note that it is the responsibility of the handler * to free the record holder when it is done * using it. In real applications, this section * MAY be used to store XML stream into databases. * * Note also that the default implementation of * the XML transformer OutputRecord method * automatically frees the record pointer. * Hence, you may invoke this method so it * handles record release for us. */ AAAAccountingXMLRecTransformer::OutputRecord(originalMsg); } ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Sending answer back to client (test purpose only)\n")); return session.SendAcctAnswer(*originalMsg);}int main(int argc, char *argv[]){ /* * This sample server test program is straight forward. * After creating an instance of the application core * and passing it the configuration file, it registers * a class factory for handling requests with application * id 0. The the configuration filename is passed in as * an argument as well as the abort flag. * * Note that a semaphore is used to mimic application * specific processing. On exit, the factory is removed * from the application core and the application cores * destructor will perform internal cleanup. * */ if (argc != 3) { ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Usage: sample_server [wait|nowait] [config file]\n")); return (1); } ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Application starting\n")); AAA_Task myTask; try { myTask.Start(10); } catch (...) { ACE_ERROR((LM_ERROR, "(%P|%t) Server: Cannot start task\n")); return (1); } AAAApplicationCore myCore; if (myCore.Open(argv[2], myTask) != AAA_ERR_SUCCESS) { ACE_ERROR((LM_ERROR, "(%P|%t) Server: Application core open error\n")); return (1); } /* abort flag */ std::string abort(argv[1]); AAASampleServer::sendAbort((abort == "wait") ? true : false); /* * application id is for this sample */ serverFactory authFactory(myCore, 10000); acctFactory acctFactory(myCore, 20000); /* * Register the factory to our application core. * All request with application id 0 will be * handled here. */ myCore.RegisterServerSessionFactory(&authFactory); myCore.RegisterServerSessionFactory(&acctFactory); /* * This will block until all session are done. * In the case of this sample, this will block * indefinitely because we did not provide an * exit routine. */ AAASampleServer::semaphore().acquire(); myCore.RemoveServerSessionFactory(&authFactory); myCore.RemoveServerSessionFactory(&acctFactory); ACE_DEBUG((LM_DEBUG, "(%P|%t) Server: Exiting\n")); return (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -