00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __DIAMETER_API_H__
00035 #define __DIAMETER_API_H__
00036
00040 #if defined (WIN32)
00041 # if defined (DIAMETERBASEPROTOCOL_EXPORTS)
00042 # define DIAMETERBASEPROTOCOL_EXPORT ACE_Proper_Export_Flag
00043 # define DIAMETERBASEPROTOCOL_EXPORT_ONLY ACE_Proper_Export_Flag
00044 # define DIAMETERBASEPROTOCOL_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
00045 # define DIAMETERBASEPROTOCOL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
00046 # else
00047 # define DIAMETERBASEPROTOCOL_EXPORT ACE_Proper_Import_Flag
00048 # define DIAMETERBASEPROTOCOL_EXPORT_ONLY
00049 # define DIAMETERBASEPROTOCOL_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
00050 # define DIAMETERBASEPROTOCOL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
00051 # endif
00052 #else
00053 # define DIAMETERBASEPROTOCOL_EXPORT
00054 # define DIAMETERBASEPROTOCOL_EXPORT_ONLY
00055 # define DIAMETERBASEPROTOCOL_SINGLETON_DECLARATION(T)
00056 # define DIAMETERBASEPROTOCOL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
00057 #endif
00058
00059 #include "aaa_application.h"
00060 #include "aaa_session_client.h"
00061 #include "aaa_session_server.h"
00062 #include "aaa_session_server_factory.h"
00063
00069
00070 class AAAApplicationCore;
00071 class AAASession;
00072
00073 typedef AAA_ServerSessionFactory AAAServerSessionFactory;
00074
00075 template<class SESSION_SERVER>
00076 class AAAServerSessionClassFactory :
00077 public AAAServerSessionFactory
00078 {
00079 public:
00080 AAAServerSessionClassFactory(AAAApplicationCore &c,
00081 diameter_unsigned32_t appId) :
00082 AAAServerSessionFactory(c.GetTask(), appId),
00083 m_Core(c) {
00084 }
00085 AAA_SessionIO *CreateInstance() {
00086 SESSION_SERVER *s = new SESSION_SERVER
00087 (m_Core, GetApplicationId());
00088 return s->IO();
00089 }
00090
00091 private:
00092 AAAApplicationCore &m_Core;
00093 };
00094
00095 typedef std::auto_ptr<AAA_Application> AAAApplicationHandle;
00096
00097 typedef void* AAASessionPayload;
00098
00099 class DIAMETERBASEPROTOCOL_EXPORT AAAApplicationCore
00100 {
00101 public:
00102 AAAApplicationCore() {
00103 }
00104 AAAApplicationCore(char *configFileName,
00105 AAA_Task &task) {
00106 Open(configFileName, task);
00107 }
00108 virtual ~AAAApplicationCore() {
00109 Close();
00110 }
00111 AAAReturnCode Open(char *configFileName,
00112 AAA_Task &task) {
00113 if (! m_Handle.get()) {
00114 m_Handle = std::auto_ptr<AAA_Application>
00115 (new AAA_Application(task));
00116 return m_Handle->Open(configFileName);
00117 }
00118 return (AAA_ERR_SUCCESS);
00119 }
00120 AAAReturnCode Close() {
00121 if (m_Handle.get()) {
00122 m_Handle->Close();
00123 m_Handle.reset();
00124 }
00125 return (AAA_ERR_SUCCESS);
00126 }
00127 AAAReturnCode RegisterServerSessionFactory
00128 (AAAServerSessionFactory *factory) {
00129 if (m_Handle.get()) {
00130 return m_Handle->RegisterServerSessionFactory
00131 (*factory);
00132 }
00133 return (AAA_ERR_SUCCESS);
00134 }
00135 AAAReturnCode RemoveServerSessionFactory
00136 (AAAServerSessionFactory *factory) {
00137 if (m_Handle.get()) {
00138 return m_Handle->RemoveServerSessionFactory
00139 (factory->GetApplicationId());
00140 }
00141 return (AAA_ERR_SUCCESS);
00142 }
00143 AAAApplicationHandle &GetAppHandle() {
00144 return m_Handle;
00145 }
00146 diameter_unsigned32_t GetNumActivePeerConnections() {
00147 if (m_Handle.get()) {
00148 return m_Handle->NumActivePeers();
00149 }
00150 return (0);
00151 }
00152 AAA_Task& GetTask() {
00153
00154 return m_Handle->Task();
00155 }
00156
00157 private:
00158 std::auto_ptr<AAA_Application> m_Handle;
00159 };
00160
00161 class DIAMETERBASEPROTOCOL_EXPORT AAAEventHandler
00162 {
00163 public:
00164 AAAEventHandler(AAAApplicationCore &c) :
00165 m_Core(c) {
00166 }
00167 virtual ~AAAEventHandler() {
00168 }
00169 virtual AAAReturnCode HandleMessage(AAAMessage &msg) {
00170 return (AAA_ERR_SUCCESS);
00171 }
00172 virtual AAAReturnCode HandleDisconnect() {
00173 return (AAA_ERR_SUCCESS);
00174 }
00175 virtual AAAReturnCode HandleTimeout() {
00176 return (AAA_ERR_SUCCESS);
00177 }
00178 virtual AAAReturnCode HandleSessionTimeout() {
00179 return (AAA_ERR_SUCCESS);
00180 }
00181 virtual AAAReturnCode HandleAuthLifetimeTimeout() {
00182 return (AAA_ERR_SUCCESS);
00183 }
00184 virtual AAAReturnCode HandleAuthGracePeriodTimeout() {
00185 return (AAA_ERR_SUCCESS);
00186 }
00187 virtual AAAReturnCode HandleAbort() {
00188 return (AAA_ERR_SUCCESS);
00189 }
00190 const AAAApplicationCore &GetApplicationCore() {
00191 return m_Core;
00192 }
00193
00194 protected:
00195 AAAApplicationCore &m_Core;
00196 };
00197
00198 class DIAMETERBASEPROTOCOL_EXPORT AAASessionMessageHandler :
00199 public AAAEventHandler
00200 {
00201 public:
00202 AAASessionMessageHandler(AAAApplicationCore &appCore,
00203 AAACommandCode cmdCode) :
00204 AAAEventHandler(appCore),
00205 m_Code(cmdCode) {
00206 }
00207 AAACommandCode GetCommandCode() {
00208 return m_Code;
00209 }
00210
00211 private:
00212 AAACommandCode m_Code;
00213 };
00214
00215 class DIAMETERBASEPROTOCOL_EXPORT AAASession :
00216 public AAAEventHandler
00217 {
00218 public:
00219 typedef std::map<AAACommandCode,
00220 AAASessionMessageHandler*>
00221 AAAMessageMap;
00222 typedef std::pair<AAACommandCode,
00223 AAASessionMessageHandler*>
00224 AAAMessageMapPair;
00225 typedef enum {
00226 EVENT_AUTH_REQUEST = 0,
00227 EVENT_AUTH_SUCCESS,
00228 EVENT_AUTH_CONTINUE,
00229 EVENT_AUTH_FAILED,
00230 EVENT_ACCT_SUCCESS,
00231 EVENT_NO_SERVICE,
00232 EVENT_PROC_ERROR
00233 } EVENT;
00234
00235 public:
00236 AAASession(AAAApplicationCore &appCore,
00237 diameter_unsigned32_t appId) :
00238 AAAEventHandler(appCore),
00239 m_Id(appId),
00240 m_LastEvent(EVENT_AUTH_SUCCESS),
00241 m_IO(NULL) {
00242 }
00243 virtual ~AAASession() {
00244 }
00245 virtual AAAReturnCode SetTimeout(time_t timeout) {
00246 return (AAA_ERR_SUCCESS);
00247 }
00248 virtual AAAReturnCode RegisterMessageHandler
00249 (AAASessionMessageHandler *handler) {
00250 AAAMessageMap::iterator i = m_MsgMap.find
00251 (handler->GetCommandCode());
00252 if (m_MsgMap.end() != i) {
00253 return (AAA_ERR_FAILURE);
00254 }
00255 m_MsgMap.insert(AAAMessageMapPair
00256 (handler->GetCommandCode(), handler));
00257 return (AAA_ERR_SUCCESS);
00258 }
00259 virtual AAAReturnCode RemoveMessageHandler
00260 (AAASessionMessageHandler *handler) {
00261 AAAMessageMap::iterator i = m_MsgMap.find
00262 (handler->GetCommandCode());
00263 if (m_MsgMap.end() != i) {
00264 m_MsgMap.erase(i);
00265 return (AAA_ERR_SUCCESS);
00266 }
00267 return (AAA_ERR_FAILURE);
00268 }
00269 virtual AAAReturnCode Update(AAASession::EVENT event) {
00270 m_LastEvent = event;
00271 return (AAA_ERR_SUCCESS);
00272 }
00273 const AAASessionHandle GetSessionHandle() {
00274 return (this);
00275 }
00276 diameter_unsigned32_t GetApplicationId() {
00277 return m_Id;
00278 }
00279 virtual void GetSessionId(diameter_octetstring_t &id) {
00280 }
00281 AAA_SessionIO *IO() {
00282 return m_IO;
00283 }
00284
00285 protected:
00286 virtual AAAReturnCode CallMsgHandler(AAAMessage &msg) {
00287 AAAMessageMap::iterator i = m_MsgMap.find
00288 (msg.hdr.code);
00289 if (m_MsgMap.end() != i) {
00290 return i->second->HandleMessage(msg);
00291 }
00292 return (AAA_ERR_FAILURE);
00293 }
00294
00295 protected:
00296 AAAMessageMap m_MsgMap;
00297 diameter_unsigned32_t m_Id;
00298 EVENT m_LastEvent;
00299 AAA_SessionIO *m_IO;
00300 };
00301
00302 class DIAMETERBASEPROTOCOL_EXPORT AAAClientSession :
00303 public AAASession,
00304 public AAA_ClientAuthSession
00305
00306 {
00307 public:
00308 AAAClientSession(AAAApplicationCore &appCore,
00309 diameter_unsigned32_t id) :
00310 AAASession(appCore, id),
00311 AAA_ClientAuthSession(appCore.GetTask(), id) {
00312 m_IO = this;
00313 }
00314 virtual ~AAAClientSession() {
00315 AAA_ClientAuthSession::End();
00316 }
00317 virtual AAAReturnCode SetTimeout(time_t timeout) {
00318 AAA_CFG_AUTH_SESSION()->lifetimeTm = (diameter_unsigned32_t)timeout;
00319 return (AAA_ERR_SUCCESS);
00320 }
00321 virtual void GetSessionId(diameter_octetstring_t &id) {
00322 char cbuf[128];
00323 Attributes().SessionId().Dump(cbuf);
00324 id = cbuf;
00325 }
00326 AAAReturnCode Start() {
00327 return Begin();
00328 }
00329 AAAReturnCode SetOptionalSIDValue(std::string optVal) {
00330 Attributes().SessionId().OptionalValue() = optVal.data();
00331 return (AAA_ERR_SUCCESS);
00332 }
00333 AAAReturnCode End() {
00334 return AAA_ClientAuthSession::End();
00335 }
00336 private:
00337 virtual AAAReturnCode RequestMsg(AAAMessage &msg) {
00338 return CallMsgHandler(msg);
00339 }
00340 virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {
00341 return CheckUpdateEvent(msg);
00342 }
00343 virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {
00344 return CallMsgHandler(msg);
00345 }
00346 virtual AAAReturnCode Disconnect() {
00347 return this->HandleDisconnect();
00348 }
00349 virtual AAAReturnCode SessionTimeout() {
00350 this->HandleTimeout();
00351 return this->HandleSessionTimeout();
00352 }
00353 virtual AAAReturnCode AuthorizationTimeout() {
00354 this->HandleAuthGracePeriodTimeout();
00355 return this->HandleAuthLifetimeTimeout();
00356 }
00357 virtual AAAReturnCode AbortSession() {
00358 return this->HandleAbort();
00359 }
00360 AAAReturnCode CheckUpdateEvent(AAAMessage &msg) {
00361 CallMsgHandler(msg);
00362 switch (m_LastEvent) {
00363 case EVENT_AUTH_SUCCESS: return AAA_ERR_SUCCESS;
00364 case EVENT_AUTH_CONTINUE: return AAA_ERR_INCOMPLETE;
00365 default: return AAA_ERR_FAILURE;
00366 }
00367 }
00368 };
00369
00370 class DIAMETERBASEPROTOCOL_EXPORT AAAServerSession :
00371 public AAASession,
00372 public AAA_ServerAuthSession
00373 {
00374 public:
00375 AAAServerSession(AAAApplicationCore &appCore,
00376 diameter_unsigned32_t id) :
00377 AAASession(appCore, id),
00378 AAA_ServerAuthSession(appCore.GetTask(), id) {
00379 m_IO = this;
00380 }
00381 virtual ~AAAServerSession() {
00382 End();
00383 }
00384 AAAReturnCode Abort() {
00385 return End();
00386 }
00387 private:
00388 virtual AAAReturnCode RequestMsg(AAAMessage &msg) {
00389 return CheckUpdateEvent(msg);
00390 }
00391 virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {
00392 return CallMsgHandler(msg);
00393 }
00394 virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {
00395 return CallMsgHandler(msg);
00396 }
00397 virtual AAAReturnCode Disconnect() {
00398 return this->HandleDisconnect();
00399 }
00400 virtual AAAReturnCode SessionTimeout() {
00401 this->HandleTimeout();
00402 return this->HandleSessionTimeout();
00403 }
00404 virtual AAAReturnCode AuthorizationTimeout() {
00405 this->HandleAuthGracePeriodTimeout();
00406 return this->HandleAuthLifetimeTimeout();
00407 }
00408 virtual AAAReturnCode AbortSession() {
00409 return this->HandleAbort();
00410 }
00411 AAAReturnCode CheckUpdateEvent(AAAMessage &msg) {
00412 CallMsgHandler(msg);
00413 switch (m_LastEvent) {
00414 case EVENT_AUTH_SUCCESS: return AAA_ERR_SUCCESS;
00415 case EVENT_AUTH_CONTINUE: return AAA_ERR_INCOMPLETE;
00416 default: return AAA_ERR_FAILURE;
00417 }
00418 }
00419 };
00420
00421 class DIAMETERBASEPROTOCOL_EXPORT AAAMessageControl
00422 {
00423 public:
00424 AAAMessageControl(AAASession *s) :
00425 m_Session(*s) {
00426 }
00427 virtual ~AAAMessageControl() {
00428 }
00429 AAAReturnCode SetResultCode(AAAMessage &response,
00430 AAAMessage &request,
00431 AAAResultCode resultCode) {
00432 AAA_MsgResultCode rcode(response);
00433 rcode.ResultCode(resultCode);
00434 return (AAA_ERR_SUCCESS);
00435 }
00436 AAAReturnCode Send(AAAMessage &msg) {
00437 std::auto_ptr<AAAMessage> newMsg(new AAAMessage);
00438 newMsg->hdr = msg.hdr;
00439 while (! msg.acl.empty()) {
00440 AAAAvpContainer *c = msg.acl.front();
00441 msg.acl.pop_front();
00442 newMsg->acl.add(c);
00443 }
00444
00445 AAA_IdentityAvpContainerWidget oHostAvp(newMsg->acl);
00446 AAA_IdentityAvpContainerWidget oRealmAvp(newMsg->acl);
00447
00448
00449 diameter_identity_t *oHost = oHostAvp.GetAvp
00450 (AAA_AVPNAME_ORIGINHOST);
00451 if (oHost == NULL) {
00452 oHostAvp.AddAvp(AAA_AVPNAME_ORIGINHOST) =
00453 AAA_CFG_TRANSPORT()->identity;
00454 }
00455 else if (oHost->length() == 0) {
00456 *oHost = AAA_CFG_TRANSPORT()->identity;
00457 }
00458
00459
00460 diameter_identity_t *oRealm = oRealmAvp.GetAvp
00461 (AAA_AVPNAME_ORIGINREALM);
00462 if (oRealm == NULL) {
00463 oRealmAvp.AddAvp(AAA_AVPNAME_ORIGINREALM) =
00464 AAA_CFG_TRANSPORT()->realm;
00465 }
00466 else if (oRealm->length() == 0) {
00467 *oRealm = AAA_CFG_TRANSPORT()->realm;
00468 }
00469
00470 return m_Session.IO()->Send(newMsg);
00471 }
00472
00473 protected:
00474 AAASession &m_Session;
00475 };
00476
00477 class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingSession :
00478 public AAASession
00479 {
00480 public:
00481 AAAAccountingSession(AAAApplicationCore &appCore,
00482 diameter_unsigned32_t id) :
00483 AAASession(appCore, id) {
00484 }
00485 virtual ~AAAAccountingSession() {
00486 }
00487 AAAReturnCode Send(AAAMessage &reqMsg) {
00488 AAAMessageControl msgCntrl(this);
00489 return msgCntrl.Send(reqMsg);
00490 }
00491 };
00492
00493 class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingClientSession :
00494 public AAAAccountingSession
00495 {
00496 private:
00497 class LocalCollector : public AAA_ClientAcctRecCollector {
00498 public:
00499 LocalCollector() :
00500 m_Session(0) {
00501 }
00502 virtual void GenerateRecord(AAAAvpContainerList &avpList,
00503 int recordType,
00504 int recordNum) {
00505 if (m_Session) {
00506 m_Session->HandleInterimRecordEvent
00507 ((AAAAccountingClientSession::RECTYPE)recordType,
00508 m_Session->m_LastPayload);
00509 }
00510 }
00511 virtual bool IsLastRecordInStorage() {
00512 return (false);
00513 }
00514 virtual bool IsStorageSpaceAvailable() {
00515 return (true);
00516 }
00517 virtual AAAReturnCode StoreLastRecord(int recordType) {
00518 return (AAA_ERR_SUCCESS);
00519 }
00520 virtual AAAReturnCode DeleteLastRecord(int recordType) {
00521 return (AAA_ERR_SUCCESS);
00522 }
00523 AAAAccountingClientSession *m_Session;
00524 friend class AAAAccountingClientSession;
00525 };
00526
00527 public:
00528 typedef enum {
00529 RECTYPE_EVENT = 1,
00530 RECTYPE_START = 2,
00531 RECTYPE_INTERIM = 3,
00532 RECTYPE_STOP = 4
00533 } RECTYPE;
00534
00535 public:
00536 AAAAccountingClientSession(AAAApplicationCore &appCore,
00537 diameter_unsigned32_t id) :
00538 AAAAccountingSession(appCore, id),
00539 m_ParentSession(appCore.GetTask(), id),
00540 m_LastPayload(NULL) {
00541 m_SubSession = std::auto_ptr<AAA_ClientAcctSubSession<LocalCollector> >
00542 (new AAA_ClientAcctSubSession<LocalCollector>(m_ParentSession));
00543 m_SubSession->RecCollector().m_Session = this;
00544 m_IO = m_SubSession.get();
00545 m_SubSession->Attributes().BackwardCompatibility() = true;
00546 }
00547 virtual ~AAAAccountingClientSession() {
00548 }
00549 AAAReturnCode SetInterimRecordInterval(RECTYPE type,
00550 int interval = 0,
00551 AAASessionPayload payload = NULL) {
00552 AAA_CFG_ACCT_SESSION()->recIntervalTm = interval;
00553 m_LastPayload = payload;
00554 switch (type) {
00555 case RECTYPE_EVENT: m_SubSession->Begin(true); break;
00556 case RECTYPE_START: m_SubSession->Begin(false); break;
00557 case RECTYPE_INTERIM: break;
00558 case RECTYPE_STOP: m_SubSession->End(); break;
00559 }
00560 return (AAA_ERR_SUCCESS);
00561 }
00562 virtual AAAReturnCode HandleInterimRecordEvent(RECTYPE type,
00563 AAASessionPayload payload) {
00564 return (AAA_ERR_SUCCESS);
00565 }
00566 private:
00567 AAA_ClientAcctSession m_ParentSession;
00568 std::auto_ptr<AAA_ClientAcctSubSession<LocalCollector> >
00569 m_SubSession;
00570 AAASessionPayload m_LastPayload;
00571 };
00572
00573 class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingRecTransformer
00574 {
00575 public:
00576 AAAAccountingRecTransformer() {
00577 }
00578 virtual ~AAAAccountingRecTransformer() {
00579 }
00580 virtual AAAReturnCode Convert(AAAMessage *msg) = 0;
00581 virtual AAAReturnCode OutputRecord(AAAMessage *originalMsg) = 0;
00582 };
00583
00584 class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingXMLRecTransformer :
00585 public AAAAccountingRecTransformer
00586 {
00587 public:
00588 AAAAccountingXMLRecTransformer() {
00589 }
00590 virtual ~AAAAccountingXMLRecTransformer() {
00591 }
00592 virtual AAAReturnCode Convert(AAAMessage *msg);
00593 virtual AAAReturnCode OutputRecord(AAAMessage *originalMsg);
00594
00595 protected:
00596 AAASessionPayload record;
00597 ACE_UINT32 record_size;
00598 };
00599
00600 class DIAMETERBASEPROTOCOL_EXPORT AAAAccountingServerSession :
00601 public AAAAccountingSession
00602 {
00603 private:
00604 class LocalStorage : public AAA_ServerAcctRecStorage
00605 {
00606 public:
00607 LocalStorage() :
00608 m_Session(0) {
00609 }
00610 virtual bool IsSpaceAvailableOnDevice() {
00611 return (true);
00612 }
00613 virtual void StoreRecord(AAAAvpContainerList &avpList,
00614 int recordType,
00615 int recordNum) {
00616 if (m_Session) {
00617 AAAMessage msg;
00618 ACE_OS::memset(&msg.hdr, 0, sizeof(msg.hdr));
00619 msg.hdr.ver = AAA_PROTOCOL_VERSION;
00620 msg.hdr.length = 0;
00621 msg.hdr.flags.r = AAA_FLG_SET;
00622 msg.hdr.flags.p = AAA_FLG_CLR;
00623 msg.hdr.flags.e = AAA_FLG_CLR;
00624 msg.hdr.code = AAA_MSGCODE_ACCOUNTING;
00625 msg.hdr.appId = m_Session->GetApplicationId();
00626
00627 while (! avpList.empty()) {
00628 AAAAvpContainer *c = avpList.front();
00629 avpList.pop_front();
00630 msg.acl.add(c);
00631 }
00632
00633 m_Session->GetTransformer()->Convert(&msg);
00634 m_Session->GetTransformer()->OutputRecord(&msg);
00635 }
00636 }
00637 AAAAccountingServerSession *m_Session;
00638 };
00639
00640 public:
00641 AAAAccountingServerSession(AAAApplicationCore &appCore,
00642 diameter_unsigned32_t id) :
00643 AAAAccountingSession(appCore, id) {
00644 m_Session = std::auto_ptr<AAA_ServerAcctSession<LocalStorage> >
00645 (new AAA_ServerAcctSession<LocalStorage>(appCore.GetTask(), id));
00646 m_Session->RecStorage().m_Session = this;
00647 m_Session->Attributes().BackwardCompatibility() = true;
00648 m_IO = m_Session.get();
00649 }
00650 virtual ~AAAAccountingServerSession() {
00651 }
00652 void SetTransformer(AAAAccountingRecTransformer *trns) {
00653 m_Transformer = trns;
00654 }
00655 AAAAccountingRecTransformer *GetTransformer() {
00656 return m_Transformer;
00657 }
00658
00659 protected:
00660 AAAAccountingRecTransformer *m_Transformer;
00661 std::auto_ptr<AAA_ServerAcctSession<LocalStorage> >
00662 m_Session;
00663 };
00664
00665 class DIAMETERBASEPROTOCOL_EXPORT AAAProxyServices
00666 {
00667 private:
00668 class LocalHandler : public AAA_ProxyHandler
00669 {
00670 public:
00671 LocalHandler(AAAEventHandler *h,
00672 diameter_unsigned32_t appId) :
00673 AAA_ProxyHandler(appId),
00674 m_ApplicationId(appId),
00675 m_Handler(h) {
00676 }
00677 virtual ~LocalHandler() {
00678 }
00679 virtual AAAReturnCode RequestMsg(AAAMessage &msg) {
00680 return m_Handler->HandleMessage(msg);
00681 }
00682 virtual AAAReturnCode AnswerMsg(AAAMessage &msg) {
00683 return m_Handler->HandleMessage(msg);
00684 }
00685 virtual AAAReturnCode ErrorMsg(AAAMessage &msg) {
00686 return m_Handler->HandleMessage(msg);
00687 }
00688 diameter_unsigned32_t &ApplicationId() {
00689 return m_ApplicationId;
00690 }
00691 protected:
00692 diameter_unsigned32_t m_ApplicationId;
00693 AAAEventHandler *m_Handler;
00694 };
00695 typedef std::map<diameter_unsigned32_t,
00696 LocalHandler*>
00697 AAAHandlerMap;
00698 typedef std::pair<diameter_unsigned32_t,
00699 LocalHandler*>
00700 AAAHandlerMapPair;
00701
00702 public:
00703 AAAProxyServices(AAAApplicationCore &appCore) :
00704 m_Core(appCore) {
00705 }
00706 virtual ~AAAProxyServices() {
00707 while (! m_HandlerMap.empty()) {
00708 AAAHandlerMap::iterator i = m_HandlerMap.begin();
00709 delete i->second;
00710 m_HandlerMap.erase(i);
00711 }
00712 }
00713 AAAReturnCode RegisterMessageHandler(diameter_unsigned32_t appId,
00714 AAAEventHandler *handler) {
00715 AAAHandlerMap::iterator i = m_HandlerMap.find(appId);
00716 if (m_HandlerMap.end() != i) {
00717 return (AAA_ERR_FAILURE);
00718 }
00719 LocalHandler *h = new LocalHandler(handler, appId);
00720 if (h) {
00721 m_HandlerMap.insert(AAAHandlerMapPair(appId, h));
00722 return (AAA_ERR_SUCCESS);
00723 }
00724 return (AAA_ERR_FAILURE);
00725 }
00726 AAAReturnCode RemoveMessageHandler(diameter_unsigned32_t appId) {
00727 AAAHandlerMap::iterator i = m_HandlerMap.find(appId);
00728 if (m_HandlerMap.end() != i) {
00729 delete i->second;
00730 m_HandlerMap.erase(i);
00731 }
00732 return (AAA_ERR_SUCCESS);
00733 }
00734
00735 protected:
00736 AAAApplicationCore &m_Core;
00737 AAAHandlerMap m_HandlerMap;
00738 };
00739
00740 #endif // __DIAMETER_API_H__
00741
00742
00743