Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_client_fsm.cxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 
00034 
00035 #include "pana_client_fsm.h"
00036 
00037 PANA_ClientStateTable PANA_PacSession::m_StateTable;
00038 typedef PANA_SessionRxInterface<PANA_Client> PANA_ClientSessionRxInterface;
00039 
00040 class PANA_CsmRxStartMsg : public PANA_ClientSessionRxInterface
00041 {
00042    public:
00043       PANA_CsmRxStartMsg(PANA_Client &c, PANA_PacSession &s) : 
00044          PANA_ClientSessionRxInterface(c), m_Session(s) { }
00045       virtual void operator()(PANA_Message &msg) { 
00046          // first level validation
00047          m_arg.ValidateMessage(msg);
00048          // second level validation
00049          if (! msg.flags().request) {
00050             throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, 
00051                                  "client received invalid message in discovery state"));
00052          }
00053          // validate sequence number
00054          if (msg.tseq() == 0 || msg.rseq() != 0) {
00055             throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, 
00056                                  "Rseq or Tseq field of start answer message is zero"));
00057          }
00058          m_arg.m_RxMessageQueue.push_back(&msg);
00059          m_Session.Notify(PANA_RX_START_REQUEST); 
00060       }
00061       virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxStartMsg(*this)); }
00062    private:
00063       PANA_PacSession &m_Session;
00064 };
00065 
00066 class PANA_CsmRxAuthMsg : public PANA_ClientSessionRxInterface
00067 {
00068    public:
00069       PANA_CsmRxAuthMsg(PANA_Client &c, PANA_PacSession &s) : 
00070          PANA_ClientSessionRxInterface(c), m_Session(s) { }
00071       virtual void operator()(PANA_Message &msg) { 
00072          // first level validation
00073          m_arg.ValidateMessage(msg);
00074          // second level validation
00075          if (! msg.flags().request) {
00076             throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, 
00077                                  "client received invalid message"));
00078          }
00079          m_arg.m_RxMessageQueue.push_back(&msg); 
00080          m_Session.Notify(PANA_RX_AUTH_REQUEST); 
00081       }
00082       virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxAuthMsg(*this)); }
00083    private:
00084       PANA_PacSession &m_Session;
00085 };
00086 
00087 class PANA_CsmRxBindMsg : public PANA_ClientSessionRxInterface
00088 {
00089    public:
00090       PANA_CsmRxBindMsg(PANA_Client &c, PANA_PacSession &s) : 
00091          PANA_ClientSessionRxInterface(c), m_Session(s) { }
00092       virtual void operator()(PANA_Message &msg) {
00093          // first level validation
00094          m_arg.ValidateMessage(msg);
00095          // second level validation
00096          if (! msg.flags().request) {
00097             throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, 
00098                                  "client received invalid message"));
00099          }
00100          // compute the event
00101          AAAAvpContainer* c_rcode = msg.avpList().search("Result-Code");
00102          if (c_rcode == NULL) {
00103             throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, 
00104                                  "PANA client received bind msg with no result code"));
00105          }
00106          diameter_unsigned32_t &rcode = (*c_rcode)[0]->dataRef(Type2Type<diameter_unsigned32_t>());
00107     
00108          AAA_Event ev = PANA_RX_BIND_FAILURE;
00109          switch (m_arg.BindResult(rcode)) {
00110             case PANA_BIND_SUCCESS_INITIAL:
00111             case PANA_BIND_SUCCESS_FINAL: ev = PANA_RX_BIND_FINAL; break;
00112             case PANA_BIND_INTERIM:       ev = PANA_RX_BIND_FIRST; break;
00113             case PANA_BIND_FAILED:        ev = PANA_RX_BIND_FAILURE; break;
00114             default: break;
00115                throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, 
00116                                     "PANA client received invalid bind event"));
00117          }
00118          m_arg.m_RxMessageQueue.push_back(&msg);         
00119          m_Session.Notify(ev);
00120       };
00121       virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxBindMsg(*this)); }
00122    private:
00123       PANA_PacSession &m_Session;
00124 };
00125 
00126 class PANA_CsmRxReAuthMsg : public PANA_ClientSessionRxInterface
00127 {
00128    public:
00129       PANA_CsmRxReAuthMsg(PANA_Client &c, PANA_PacSession &s) : 
00130          PANA_ClientSessionRxInterface(c), m_Session(s) { }
00131       virtual void operator()(PANA_Message &msg) {
00132          // first level validation
00133          m_arg.ValidateMessage(msg);
00134          // second level validation
00135          if (msg.flags().request && m_Session.IsSessionResumption()) {
00136             m_Session.Notify(PANA_RX_REAUTH_REQUEST);
00137          }
00138          else {
00139             m_arg.m_RxMessageQueue.push_back(&msg); 
00140             m_Session.Notify(PANA_RX_REAUTH_ANSWER); 
00141          }
00142       };
00143       virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxReAuthMsg(*this)); }
00144    private:
00145       PANA_PacSession &m_Session;
00146 };
00147 
00148 class PANA_CsmRxTermMsg : public PANA_ClientSessionRxInterface
00149 {
00150    public:
00151       PANA_CsmRxTermMsg(PANA_Client &c, PANA_PacSession &s) : 
00152          PANA_ClientSessionRxInterface(c), m_Session(s) { }
00153       virtual void operator()(PANA_Message &msg) {
00154          // first level validation
00155          m_arg.ValidateMessage(msg);
00156          // second level validation
00157          m_arg.m_RxMessageQueue.push_back(&msg); 
00158          (msg.flags().request) ? m_Session.Notify(PANA_RX_TERM_REQUEST) :
00159                                  m_Session.Notify(PANA_RX_TERM_ANSWER); 
00160       };
00161       virtual PANA_ClientSessionRxInterface *clone() { return (new PANA_CsmRxTermMsg(*this)); }
00162    private:
00163       PANA_PacSession &m_Session;
00164 };
00165 
00166 void PANA_PacSession::InitializeMsgMaps()
00167 {
00168    PANA_CsmRxStartMsg startMsg(m_Client, *this);
00169    m_MsgHandlers.Register(PANA_MTYPE_START, startMsg);
00170 
00171    PANA_CsmRxAuthMsg authMsg(m_Client, *this);
00172    m_MsgHandlers.Register(PANA_MTYPE_AUTH, authMsg);
00173 
00174    PANA_CsmRxBindMsg bindMsg(m_Client, *this);
00175    m_MsgHandlers.Register(PANA_MTYPE_BIND, bindMsg);
00176 
00177    PANA_CsmRxReAuthMsg reAuthMsg(m_Client, *this);
00178    m_MsgHandlers.Register(PANA_MTYPE_REAUTH, reAuthMsg);
00179 
00180    PANA_CsmRxTermMsg termMsg(m_Client, *this);
00181    m_MsgHandlers.Register(PANA_MTYPE_TERM, termMsg);
00182 }
00183 
00184 void PANA_PacSession::FlushMsgMaps()
00185 {
00186    m_MsgHandlers.Remove(PANA_MTYPE_START);
00187    m_MsgHandlers.Remove(PANA_MTYPE_AUTH);
00188    m_MsgHandlers.Remove(PANA_MTYPE_BIND);
00189    m_MsgHandlers.Remove(PANA_MTYPE_REAUTH);
00190    m_MsgHandlers.Remove(PANA_MTYPE_TERM);
00191 }
00192 
00193 

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5