Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

eap_peerfsm.hxx

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 // $Id: eap_peerfsm.hxx,v 1.30 2004/06/17 21:13:36 yohba Exp $
00034 
00035 // eap_peerfsm.hxx:  Peer state machine
00036 // Written by Yoshihiro Ohba
00037 
00038 #ifndef __EAP_PEERFSM_HXX__
00039 #define __EAP_PEERFSM_HXX__
00040 
00041 #include <memory>
00042 #include <ace/Basic_Types.h>
00043 #include <ace/Task.h>
00044 #include <ace/Activation_Queue.h>
00045 #include <ace/Method_Request.h>
00046 #include <ace/Future.h>
00047 #include "eap.hxx"
00048 #include "eap_fsm.hxx"
00049 
00050 typedef ACE_Future<std::string> EapFutureStringResult;
00051 
00052 class EapPeerSwitchStateMachine;
00053 class EapSession;
00054 
00057 class EAP_EXPORTS InputIdentityMethodRequest : public ACE_Method_Request
00058 {
00059 public:
00060   InputIdentityMethodRequest(EapPeerSwitchStateMachine *sm,
00061                              EapFutureStringResult &futureResult)
00062     : stateMachine(sm), futureResult(futureResult) {}
00063   int call();
00064 
00065 private:
00066   EapPeerSwitchStateMachine *stateMachine;
00067   EapFutureStringResult futureResult;
00068 };
00069 
00072 class EAP_EXPORTS EapInputIdentityTask : public ACE_Task<ACE_MT_SYNCH>
00073 {
00074 public:
00075   EapInputIdentityTask() {}
00076 
00077   void Set(EapPeerSwitchStateMachine *sm) { stateMachine = sm; }
00078 
00079   ~EapInputIdentityTask() { ACE_Thread::kill(thread, 2); }
00080   virtual int open()
00081   {
00082     return activate(THR_NEW_LWP);
00083   }
00084   virtual int close(unsigned long flags = 0)
00085   {
00086     return 0;
00087   }
00088   virtual int svc()
00089   {
00090     thread = ACE_Thread::self();
00091     do {
00092       std::auto_ptr<ACE_Method_Request> methodRequest(activationQueue.dequeue());
00093       if (methodRequest->call() == -1)
00094         break;
00095     } while(0);
00096     return 0;
00097   }
00098   
00099   EapFutureStringResult InputIdentity()
00100   {
00101     EapFutureStringResult futureResult;
00102     activationQueue.enqueue
00103       (new InputIdentityMethodRequest(stateMachine, futureResult));
00104     return futureResult;
00105   }
00106   
00107 private:
00108   EapPeerSwitchStateMachine *stateMachine;
00109   ACE_Activation_Queue activationQueue;
00110   ACE_thread_t thread;
00111 };
00112 
00113 
00116 class EAP_EXPORTS EapPeerSwitchStateMachine : 
00117   public EapSwitchStateMachine,
00118   public EapStateMachine<EapPeerSwitchStateMachine>
00119 {
00120   friend class EapPeerSwitchStateTable_S;
00121 public:
00122 
00123   void Start() throw(AAA_Error);
00124 
00125   inline void Notify(AAA_Event ev)
00126   {
00127     try {
00128       EapStateMachine<EapPeerSwitchStateMachine>::Notify(ev);
00129     }
00130     catch (int i) {
00131           ACE_UNUSED_ARG(i);
00132       EAP_LOG(LM_DEBUG, "Nofify() failed.\n");
00133       Abort();
00134     }
00135   }
00136 
00139   void Receive(AAAMessageBlock*);
00140 
00143   virtual void Success()=0;
00144 
00147   virtual void Failure()=0;
00148 
00150   virtual void Notification(std::string &str)=0;
00151 
00154   virtual std::string& InputIdentity()=0;
00155 
00157   inline bool& NotificationAllowed() { return notificationAllowed; }
00158 
00160   inline std::string& NotificationString() { return notificationStr; }
00161 
00163   inline ACE_UINT16& AuthPeriod() { return authPeriod; }
00164 
00166   inline ACE_Byte& LastIdentifier() { return lastIdentifier; }
00167 
00169   inline bool& LastIdValidity() { return lastIdValidity; }
00170 
00172   inline EapType& ReqMethod() { return reqMethod; }
00173 
00175   inline bool& ReceivedFirstRequest() { return receivedFirstRequest; }
00176 
00178   inline EapInputIdentityTask& InputIdentityTask() { return inputIdentityTask; }
00179 
00181   inline EapFutureStringResult& FutureIdentity() { return futureIdentity; }
00182 
00184   inline int InputIdentityTimerType() { return inputIdentityTimerType; }
00185 
00187   enum EapPeerDecision {
00188     FAIL,
00189     COND_SUCC,
00190     UNCOND_SUCC
00191   };
00192 
00193   inline EapPeerDecision& Decision() { return decision; }
00194 
00200   enum EapPeerMethodState {
00201     NONE,
00202     INIT,
00203     CONT,
00204     MAY_CONT,
00205     DONE,
00206   };
00207 
00208   inline EapPeerMethodState& MethodState() { return methodState; }
00209 
00211   enum event {
00212     EvRxMsg=-1,          // Message reception event passed from
00213                          // application via EapSession::Receive().
00214     EvSgPortEnabled=-2,  // Port enabled event passed from application.
00215     EvSgValidReq=-3,     // Integrity check sucess event passed from
00216                          // methods.
00217     EvSgInvalidReq=-4    // Integrity check failure event passed from
00218                          // methods.
00219   };
00220 
00221 
00222 protected:
00223   EapPeerSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h);
00224 
00225   ~EapPeerSwitchStateMachine() {}
00226 
00229   ACE_Byte lastIdentifier;
00230 
00235   bool lastIdValidity;
00236 
00238   static const ACE_UINT16 defaultAuthPeriod;
00239 
00241   ACE_UINT16 authPeriod;
00242 
00245   bool receivedFirstRequest;
00246 
00248   bool notificationAllowed;
00249 
00251   std::string notificationStr;
00252 
00254   EapType reqMethod;
00255 
00257   EapInputIdentityTask inputIdentityTask;
00258 
00261   EapFutureStringResult futureIdentity;
00262 
00264   int inputIdentityTimerType;
00265 
00267   EapPeerDecision decision;
00268 
00270   EapPeerMethodState methodState;
00271 };
00272 
00273 #endif // __EAP_PEERFSM_HXX__

Generated on Fri Jun 25 19:16:16 2004 for EAP State Machine by doxygen 1.3.5