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
00035
00036
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,
00213
00214 EvSgPortEnabled=-2,
00215 EvSgValidReq=-3,
00216
00217 EvSgInvalidReq=-4
00218
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__